2016-04-28 46 views
0

我想在按钮内添加图标。这里是我的代码如何在按钮内显示图标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(); 
} 

这里的问题是,该图标没有出现在第一,当我点击该按钮出现。

这里有什么问题?

+10

你加入printbutton_click事件中的图标,而不是将其定义表格initializecomponents –

+0

@SebastianSchulz我如何准确地做? –

回答

0

你加入printbutton_click事件中的图标,而不是将其定义表格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非常感谢:) –

0

像这样

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. 
    } 
相关问题