Seid Gegrüßt!
Ich habe folgendes Problem:
Ich möchte ein BitMap eines UserControls, das vierschiedene Controls enthält, erzeugen. Mit Freude fand ich die DrawToBitMap-Methode. Diese erzeugt auch ein BitMap. Doch leider gibt es bei der Darstellung der Textbox-Controls Probleme. Die werden nicht angezeigt, wenn ich die UserControl-Klasse als Container benutze.
Eine Lösung des Problems ist, anstatt des UserControl ein Form-Control zu benutzen, dieses sichtbar zu machen und die DrawToBitMap Methode aufzurufen. Die BitMap enthält dann alle Controls korrekt dargestellt. Das Problem ist, dass die Form kurz angezeigt werden muss.
Kennt jemand das Problem? Hat jemand dafür eine Lösung? Gehe ich vollkommen falsch an die Sache ran?
Zum Verständnis kurzer PseudoCode:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
| public void CreateBitMap() { TextBox textBox = new TextBox(); textBox.Location = new System.Drawing.Point(0, 0); textBox.Name = "textBox1"; textBox.Size = new System.Drawing.Size(100, 20); textBox.Text = "ABC";
Form toDraw = new Form(); toDraw.Size = new Size(200, 200); toDraw.Controls.Add(textBox); toDraw.Visible = true;
Graphics myGraphics = toDraw.CreateGraphics(); Bitmap bitMap = new Bitmap(toDraw.Size.Width, toDraw.Size.Height, myGraphics); toDraw.DrawToBitmap(bitMap, new Rectangle(0, 0, testControl.Width, testControl.Height));
} |
MfG
Thomas.
Moderiert von
Christian S.: C#-Tags hinzugefügt