Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[c#] Help - GUI

Newbie Spellweaver
Joined
Sep 21, 2014
Messages
33
Reaction score
0
C# Need help

Any Idea, how to achieve smooth transition in c#? Because its so flickery when you put an image as background on a form.

heres my code:

View attachment SlideFormAnimation.rar
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace SlideFormAnimation
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();


this.tm2.Enabled = true;
gbox1.Visible = false;





}
int tx1 = 49;




private void timer1_Tick(object sender, EventArgs e)
{



if (tx1 > 300)
{
timer1.Stop();
}
else
{



this.gbox1.Size = new Size(this.gbox1.Width,tx1);
tx1 += 2;
gbox1.Show();
}
}


private void timer2_Tick(object sender, EventArgs e)
{
if (this.Height >= 400) this.tm2.Enabled = false;
else this.Height += 66;
timer1.Start();

}




}
}
 

Attachments

You must be registered for see attachments list
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
I didn't test your project but:

Most of the time when you encounter flickering it is because the controls are drawn directly onto the device without any synchronization with the Monitor Refresh Rate. So while the dialog (rather the UI thread) is busy drawing the components onto the form / dialog / whatever you have there, the monitor already refreshes and like half of the dialog is drawn. As monitors refresh very frequently this looks like the controls flicker around (when they re-draw themselves).

There are several approaches to prevent this and it's also dependent on your situation. I can highly suggest double buffering where the controls are drawn virtually (in the memory) before an updated result is being drawn to the screen.

Here is a related MSDN article that describes how to enable double buffering for your form application:

Basically add this:
Code:
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
to the constructor of your Form and try again.
 
Newbie Spellweaver
Joined
Sep 21, 2014
Messages
33
Reaction score
0
I didn't test your project but:

Most of the time when you encounter flickering it is because the controls are drawn directly onto the device without any synchronization with the Monitor Refresh Rate. So while the dialog (rather the UI thread) is busy drawing the components onto the form / dialog / whatever you have there, the monitor already refreshes and like half of the dialog is drawn. As monitors refresh very frequently this looks like the controls flicker around (when they re-draw themselves).

There are several approaches to prevent this and it's also dependent on your situation. I can highly suggest double buffering where the controls are drawn virtually (in the memory) before an updated result is being drawn to the screen.

Here is a related MSDN article that describes how to enable double buffering for your form application:

Basically add this:
Code:
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
to the constructor of your Form and try again.


{
InitializeComponent();

DoubleBuffered = true;

this.tm2.Enabled = true;
gbox1.Visible = false;





}

i have already tried putting it in initialization.
but still its so laggy when you have an image in background.
 
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
Then it might be the case that the control you use for the background draws, just like any other control, in a random order. With that, it could overdraw some other controls. Or you need to set the double buffering property for the control that draws the background explicitly.

Would you mind sharing the whole basic drawing source code you use? This will make it much easier to debug the problem.
Also, I don't like .exe files I have no clue about for obvious security reasons.
 
Back
Top