473,388 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Moving Panel

Greetings

I would like to knowhow can I put a sliding panel...
I've done this:

if (panel1.Width < 300)
{
while (panel1.Width < 300)
{
panel1.Width = panel1.Width + 40;
ButtonPosition();
this.Invalidate();
}
}
else
{
while (panel1.Width 0)
{
panel1.Width = panel1.Width - 40;
ButtonPosition();
this.Invalidate();
}
}

The problem is that the content of the panel flickers a lot...

I've already tried the function Invalidate() but that doesn't give me a
fluid moviment... how can I do it?
Aug 29 '06 #1
2 9351
Hi Diogo,

I created a sample project to test with, with a single Form and a Panel on
it colored blue (for visibility). I put an image box in the Panel, to give
it something extra to draw. I created a button to open and close the Panel,
and the code is as follows:

public partial class Form1 : Form
{
private bool close = true;
private bool moving = false;

private void btnSize_Click(object sender, EventArgs e)
{
if (moving)
{
btnSize.Text = (close ? "Open" : "Close");
moving = false;
Thread.Sleep(50);
setClose(!close);
}
if (close)
{
moving = true;
while (panel1.Width panel1.MinimumSize.Width && moving)
{
panel1.Width -= 10;
Thread.Sleep(5);
Application.DoEvents();
}
setClose(false);
moving = false;
btnSize.Text = "Open";
}
else
{
moving = true;
while (panel1.Width < panel1.MaximumSize.Width && moving)
{
panel1.Width += 10;
Thread.Sleep(5);
Application.DoEvents();
}
setClose(true);
moving = false;
moving = false;
btnSize.Text = "Close";
}
}

private void setClose(bool value)
{
close = value;
status1.Text = (close ? "Close" : "Open");
}

protected override void OnClosing(CancelEventArgs e)
{
moving = false;
base.OnClosing(e);
}

public Form1()
{
InitializeComponent();
}
}

Basically, this does what your code does, with a couple of minor exceptions:

a. Invalidate is not called.
b. The width changed per iteration is smaller.

I experienced no flickering issues, even when I did call Invalidate on the
Form, but that is not necessary. I suspect that the call to Invalidate for
the Form may be causing your problems. When you call Invalidate on the Form,
it forces the entire Form to be redrawn. If you app has many more Controls
than mine (highly likely), this could cause the flickering.

Generally speaking, flickering is caused by too much of the Form needing to
be redrawn in a given painting interval. Invalidate should only be called
when necessary. That is, don't use it (by default) unless you see some
behavior that requires it. In addition, when you call Invalidate on a
Control, do so as sparingly as possible. There is an override of the
Invalidate method that takes a rectangle as an argument. If possible, only
Invalidate the smallest rectangle that needs to be redrawn. And remember
that every Control has an Invalidate method. You should almost never have to
call Invalidate on the entire Form.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

It takes a tough man to make a tender chicken salad.
"Diogo Alves - Software Developer"
<Di*************************@discussions.microsoft .comwrote in message
news:42**********************************@microsof t.com...
Greetings

I would like to knowhow can I put a sliding panel...
I've done this:

if (panel1.Width < 300)
{
while (panel1.Width < 300)
{
panel1.Width = panel1.Width + 40;
ButtonPosition();
this.Invalidate();
}
}
else
{
while (panel1.Width 0)
{
panel1.Width = panel1.Width - 40;
ButtonPosition();
this.Invalidate();
}
}

The problem is that the content of the panel flickers a lot...

I've already tried the function Invalidate() but that doesn't give me a
fluid moviment... how can I do it?

Aug 29 '06 #2
hum... that produced a less fluid animation... it's jumping..

:( pretty bad... do you have any other sugestions?

"Kevin Spencer" wrote:
Hi Diogo,

I created a sample project to test with, with a single Form and a Panel on
it colored blue (for visibility). I put an image box in the Panel, to give
it something extra to draw. I created a button to open and close the Panel,
and the code is as follows:

public partial class Form1 : Form
{
private bool close = true;
private bool moving = false;

private void btnSize_Click(object sender, EventArgs e)
{
if (moving)
{
btnSize.Text = (close ? "Open" : "Close");
moving = false;
Thread.Sleep(50);
setClose(!close);
}
if (close)
{
moving = true;
while (panel1.Width panel1.MinimumSize.Width && moving)
{
panel1.Width -= 10;
Thread.Sleep(5);
Application.DoEvents();
}
setClose(false);
moving = false;
btnSize.Text = "Open";
}
else
{
moving = true;
while (panel1.Width < panel1.MaximumSize.Width && moving)
{
panel1.Width += 10;
Thread.Sleep(5);
Application.DoEvents();
}
setClose(true);
moving = false;
moving = false;
btnSize.Text = "Close";
}
}

private void setClose(bool value)
{
close = value;
status1.Text = (close ? "Close" : "Open");
}

protected override void OnClosing(CancelEventArgs e)
{
moving = false;
base.OnClosing(e);
}

public Form1()
{
InitializeComponent();
}
}

Basically, this does what your code does, with a couple of minor exceptions:

a. Invalidate is not called.
b. The width changed per iteration is smaller.

I experienced no flickering issues, even when I did call Invalidate on the
Form, but that is not necessary. I suspect that the call to Invalidate for
the Form may be causing your problems. When you call Invalidate on the Form,
it forces the entire Form to be redrawn. If you app has many more Controls
than mine (highly likely), this could cause the flickering.

Generally speaking, flickering is caused by too much of the Form needing to
be redrawn in a given painting interval. Invalidate should only be called
when necessary. That is, don't use it (by default) unless you see some
behavior that requires it. In addition, when you call Invalidate on a
Control, do so as sparingly as possible. There is an override of the
Invalidate method that takes a rectangle as an argument. If possible, only
Invalidate the smallest rectangle that needs to be redrawn. And remember
that every Control has an Invalidate method. You should almost never have to
call Invalidate on the entire Form.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

It takes a tough man to make a tender chicken salad.
"Diogo Alves - Software Developer"
<Di*************************@discussions.microsoft .comwrote in message
news:42**********************************@microsof t.com...
Greetings

I would like to knowhow can I put a sliding panel...
I've done this:

if (panel1.Width < 300)
{
while (panel1.Width < 300)
{
panel1.Width = panel1.Width + 40;
ButtonPosition();
this.Invalidate();
}
}
else
{
while (panel1.Width 0)
{
panel1.Width = panel1.Width - 40;
ButtonPosition();
this.Invalidate();
}
}

The problem is that the content of the panel flickers a lot...

I've already tried the function Invalidate() but that doesn't give me a
fluid moviment... how can I do it?


Aug 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jay | last post by:
I need to be able to move a Panel on a windows Form at run time using the mouse. I have tried adding a MouseDown event handler to the Panel and then within the MouseDown handler adding a MouseMove...
2
by: °Ë´óɽÈË | last post by:
Hi, I want to realize moving contols in a panel, just like Form Desinger in VS.NET. How shall I realize it? Thank you. Jerry
0
by: Mark Nijhof | last post by:
Hello, I made a small app that has those nice moving panels like Visual Studio has. Now all goes fine until I open one of them that has a lot of child controls in it. Actually it has one...
1
by: Jon | last post by:
Hi, How do you make a panel which can move into the screen and move out, something like the Solution Explorer/Propertise/Toolbox etc which it will auto hide itsels on the side on the sreen? ...
7
by: Webbee | last post by:
What I need is to be able to get the location of a panel on the status bar. When I was looking to add a progressbar to the statusbar I learned that the best and maybe only way to do this is by...
0
by: MrNobody | last post by:
I have a custom Panel which will have smaller custom Panels added and drawn within it. I want to be able to re-order the arrangement of the inner Panels using drag n drop, and I want to do this...
1
by: mrabie | last post by:
Hi All, I know this has been discussed before but i can't really find an answer to what i want to do. I am developing an application for touchscreen using C#. It's going to be a fullscreen...
0
by: adarshyam | last post by:
hi .. can u pls temme the procedure how to make a panel (containing dynamic controls) visible in a position in 1st view and change the same panel s position in the next view ..
6
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I'm making a screenshot program that lets me position a secondary form and press a button in the main form to take a screenshot where the second form is located. I have the second form set to have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.