Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# resize
hey guys,
 
if you reccognized im new here and i would appriciate that you tell me if im doing something wrong here!
Thank you =)
 
So i will come to my problem, imagine a window with pictureboxes and amount of click events etc.
 
Now i have inserted a panel with the height of the window, and the width of 20px.
I want that this panel, gets an event onclick, hover, mouseleave, drag. And it should always be in the front, so that the pictureboxes are invisible, just the panel would be visible.
 
- if i hover that panel it should pop a little bit out, like 20px.
 
- if i click that panel it should get the size of the programming window.
 
- mouseleave, the panel should return like it was, but thats not the problem.
 
- and just for fun, afterwards, i would like to create a drag event, if i drag a little picturebox in the panel like 200px to the left side, the panel should cover the whole window, like the click event.
 

So i hope i have given you the right informations for what i want, if not please tell me!
 
Thank you
 
Greets niko
Posted 8-Oct-12 22:51pm
Comments
OriginalGriff at 9-Oct-12 3:56am
   
And what have you tried?
Nikola Kalakovic at 9-Oct-12 4:16am
   
following i have tried: private void Panel_Extras_MouseHover(object sender, EventArgs e)
{
Panel_Extras.Height = 750;
Panel_Extras.Width = 40;
Panel_Extras.Location = new Point(1410,0);

}
 
but thats bad in my mind, cause the window could change his width, this i ment by: new Point and the value 1410. I would ruther prefere to tell them, get window width, and pop +2% out.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

MouseHover[^], MouseClick[^] and MouseLeave[^] are all events of the System.Windows.Forms.Panel[^] class. You can subscribe a method to each of them and in those methods, set the panel's Location[^] and Size[^] properties as you wish.
  Permalink  
Comments
Nikola Kalakovic at 9-Oct-12 4:17am
   
if i accept your solution the thread goes solved or you just get points for good awnsers?
lukeer at 9-Oct-12 4:32am
   
I'll get points _and_ the thread will be marked as solved.
niko_tells at 9-Oct-12 4:35am
   
but that aint solved ^^, for the future what should i do if im in that case again? give you 5 stars or mark as solved, even if my thread isnt solved?
lukeer at 9-Oct-12 4:42am
   
I'm happy with 5 stars if the answer is good. Accept the solution if it answers your question completely. Or you can accept several solutions that answer your question when combined.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

"following i have tried:
private void Panel_Extras_MouseHover(object sender, EventArgs e)
		{
			Panel_Extras.Height = 750;
			Panel_Extras.Width = 40;
			Panel_Extras.Location = new Point(1410,0);
			
		}
 
but thats bad in my mind, cause the window could change his width, this i ment by: new Point and the value 1410. I would ruther prefere to tell them, get window width, and pop +2% out."
 
Indeed it is: try
Panel_Extras.Height = Height;
Panel_Extras.Width = 40;
PanelExtras.Location = new Point((int) ((float) Width * 1.02), 0);
Width and Height will pick up the Form width and height (or whatever the current class is based on)
  Permalink  
Comments
niko_tells at 9-Oct-12 4:32am
   
Thank you for your very good awnser!
Ok i understand width and height now, but 1.02, 1 stays for increasing, 0 would be for decreasing? .02 is ment by 2%. I wanted to change the value, but it doesnt really change anything, how can i know wich class is based on that?
 
ps.: if i accept your awnser this thread is solved? if yes, i cant to it, cause there are awnseres open.
lukeer at 9-Oct-12 4:38am
   
"Width * 1.02" is the same as "102% of Width". Or "Two percent more than Width".
niko_tells at 9-Oct-12 4:52am
   
ah i could have the reason why it doesnt increases the width, the panel is on the right border of the window and should increse the size/position to left. So i tried instead of 1.02 -> 0.98. But that doesnt change, its the same funktion like 1.02. I have also tried 10.00, to discover if this is a child of another element and not of form. And 10.00 also didnt change nothing, its like 1.02. Now getting depressed ^^
OriginalGriff at 9-Oct-12 5:02am
   
It is possible that 1.02 is not changing anything because the numbers involved are too small and the point is an integer value: adding 2% to a small number may not generate a different integer!
 
Bear in mind that Width is the container control width - so you don't really want to use that in order to "pop" it out a little - you want to move it a small amount relative to it's original position.
 
So try storing it's location (outside the MoveHover event handler) and set it to that plus (say) 5 pixels in both X and Y. That should produce a better "Pop" effect. (Don't forget that MouseHover can occur more than once, so you probably don't want to add an amount each time - hence storing the original location outside the event handler)
niko_tells at 9-Oct-12 5:27am
   
For some reasons its hard to understand you, my english isnt the best -.-
 
I think you will advice me that i create a variable out of the hover. ex.: int PopX =5
 
And than entering this variable like that into hover: PanelExtras.Location = new Point((int) (PopX, 0);
 
I know that this is not possible.
 
To the comment with width, thank you for that, so i conclused that i need another referenze for width, i tried to get the form1 width but that command is also not possible.
OriginalGriff at 9-Oct-12 5:39am
   
Sorry if you don't understand - I will try to explain in simpler English. Please tell me if it still doesn't make sense!
 
What I'm suggesting is that you save the original location of the panel outside the hover event handler:
private Point origLocation;
...
origLocation = Panel_Extra.Location;
...
(You can do that in the MouseEnter handler)
Then in your hover handler, you use that value:
Panel_Extra.Location = new Point(origLocation.X + 5, origLocation.Y + 5);
Then set it back to the original location when your mouse leaves the panel, via the MouseLeave event:
Panel_Extra.Location = origLocation;
niko_tells at 9-Oct-12 6:45am
   
Thank you for extra explaination for me =)
 
here is the whole solution:
 
Point defaultPoint = new Point(1433, 5);
Point MaxPoint = new Point(0, 0);
 
private void Panel_Extras_MouseHover(object sender, EventArgs e)
{
Panel_Extras.Height = Height;
Panel_Extras.Width = Width;
Panel_Extras.Location = new Point((defaultPoint.X - 20), 5);

}
 
private void Panel_Extras_MouseLeave(object sender, EventArgs e)
{
Panel_Extras.Height = Height;
Panel_Extras.Width = Width;
Panel_Extras.Location = new Point(defaultPoint.X, 5);
}
 
private void Panel_Extras_Click(object sender, EventArgs e)
{
Panel_Extras.Location = MaxPoint;
}
 
There is just one little point, that i dont like, defaultpoint(1433,5) isnt dynamic.
OriginalGriff at 9-Oct-12 8:08am
   
:laugh: - then don't do it. Use the MouseEnter handler to set the initial position, or set it in the Form Load event and update it in teh Form Resize.
 
I would agree - never use "magic numbers" like that - they are normally going to cause problems later!
niko_tells at 9-Oct-12 10:05am
   
haha right, thanks ;)
 
thanks for helping alot =)
 
Have a nice day ;)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If you have a panel then it will use like it . . .
 
pnlPopUp.Visible = true;
pnlPopUp.Height = 1100;
pnlOffer.Style.Add("top", "180px");
pnlOffer.Visible = true;
  Permalink  
v2
Comments
niko_tells at 9-Oct-12 4:41am
   
im not sure if this is "dynamic" cause if i change the window width your code would look crappy

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 499
1 Maciej Los 325
2 Sergey Alexandrovich Kryukov 234
3 DamithSL 233
4 Mathew Soji 195
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100