2016-04-28 4 views
0

Ich möchte Symbol in einer Schaltfläche hinzufügen. Hier ist mein Codewie Symbol in einer Schaltfläche zu zeigen WindowsForms

private void Printbutton_Click(object sender, EventArgs e) 
{ 
    // Assign an image to the button. 
    Printbutton.Image = Image.FromFile("D:\\Downloads\\print.png"); 

    // Align the image and text on the button. 
    Printbutton.ImageAlign = ContentAlignment.MiddleRight; 
    Printbutton.TextAlign = ContentAlignment.MiddleLeft; 

    // Give the button a flat appearance. 
    Printbutton.FlatStyle = FlatStyle.Flat; 

    if (SetupThePrinting()) 
     printDocument1.Print(); 
} 

Das Problem hierbei ist, dass das Symbol nicht auf dem ersten angezeigt wird, es erscheint, wenn ich auf die Schaltfläche klicken.

Was ist hier falsch?

+10

Sie das Symbol in printbutton_click Ereignisse statt definiert es in dem Formular –

+0

@SebastianSchulz InitializeComponents hinzugefügt Wie ich mach es genau? –

Antwort

0

Sie hinzugefügt, um das Symbol in printbutton_click Ereignisse statt definieren es in dem Formular InitializeComponents

public Form2() 
    { 
     InitializeComponent(); 

     // Assign an image to the button. 
     Printbutton.Image = Image.FromFile("D:\\Downloads\\print.png"); 
     // Align the image and text on the button. 
     Printbutton.ImageAlign = ContentAlignment.MiddleRight; 
     Printbutton.TextAlign = ContentAlignment.MiddleLeft; 
     // Give the button a flat appearance. 
     Printbutton.FlatStyle = FlatStyle.Flat; 
    } 

    private void Printbutton_Click(object sender, EventArgs e) 
    { 
     if (SetupThePrinting()) 
      printDocument1.Print(); 
    } 
+0

@Sebatian Schulz Vielen Dank :) –

0

Gefallen Sie diesen

public Form1() 
    { 
     InitializeComponent(); 

     // Assign an image to the button. 
     button1.Image = Image.FromFile("C:\\Yourfolder"); 
     // Align the image and text on the button. 
     button1.ImageAlign = ContentAlignment.MiddleRight; 
     button1.TextAlign = ContentAlignment.MiddleLeft; 
     // Give the button a flat appearance. 
     button1.FlatStyle = FlatStyle.Flat; 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     // Your print code. 
    } 
Verwandte Themen