3
Answers

Form background image flicker C# .Net

Sondre Garmo

Sondre Garmo

19y
18k
1
Programming language: Visual C# .Net

Hello!
My program have a form with a listbox, combobox, progressbar, groupbox and labels.
I want to have a background image (jpg) over the entire form.
The other controls have been set to Transparent BackColor.

BackgroundImage property isn't so good solution I think.
My program flicker if I open it or if another program is over and I set focus on my program.
Both the picture and all the other controls on the form flicker.

Can someone give me a better or perfect solution what I can do?
Should I use GDI or directx, how to do that?

Thanks!
Answers (3)
2
Roy S

Roy S

NA 1.1k 0 12y
If I get it correctly you want to add a button to the form, from code and not with the designer.

It's not that hard. Just add an eventhandler for the load event of your form. Instantiate a button, set some properties of that button and add it to the control collection of the form.

private void Form1_Load(object sender, EventArgs e)
{
    //instantiate new Button
    Button btnNew = new Button();

    //edit some properties.. size, location, text
    btnNew.Text = "Hello world";
    btnNew.Size = new Size(100, 20);
    btnNew.Location = new Point(50, 70);

    //add an event handler for the click event
    btnNew.Click += btnNewClick;

    //add the button to the controls
    this.Controls.Add(btnNew);
}

private void btnNewClick(object sender, EventArgs e)
{
    //method for the click event.
    MessageBox.Show("You clicked the button");
}
Accepted
0
younis abdeljawwad

younis abdeljawwad

NA 73 72.2k 12y
thx, it is work correctly