Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have 1 panel in windows form, set to a certain width and height, and want to recreate something similar to how you can adjust width and the height the paint box in Microsoft paint. How do I make a panel resizable for the user, so that they can resize from both width and height?
You can create your own UserControl (e.g. called ResizablePanel), use a Panel in it, set its Anchor to Top, Bottom, Left, Right.
Resize that Panel so it nearly covers all the corners of your UserControl. The black part in this picture is the UserControl, the white part, your Panel.
Then you have to use 3 Events: ResizablePanel_MouseDown, ResizablePanel_MouseMove and ResizablePanel_MouseUp.
private void ResizablePanel_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isResizeMode = true;
}
}
private void ResizablePanel_MouseMove(object sender, MouseEventArgs e)
{
if (isResizeMode)
{
this.Size = new Size(e.X, e.Y);
}
}
private void ResizablePanel_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isResizeMode = false;
}
}
Now you can click on your ResizablePanel border to resize it directly.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 days ago.
Improve this question
How is it possible to use a var after "this."
i want to set the Background color of a TextBlock to Blue.
Brush blue = new SolidColorBrush(Colors.LightBlue); //Working Fine
//Click on the TextBlock (Working Fine)
private void MouseDown_TextBlock(object sender, MouseButtonEventArgs e)
{
var stand = ((TextBlock)sender).Name; //Here i am getting the Name of the TextBlock (Working Fine)
this.stand.Background = blue; //This is not working here
}
If you want to access the control you receive as Sender in an event, just cast it to the appropriate class:
private void textBlock1_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get sender as TextBlock
TextBlock standTextBlockFromSender = (TextBlock)sender;
standTextBlockFromSender.Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255));
}
If you want to find the control by name, you can use the FindName method.
private void textBlock1_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get name of sender
string stand = ((TextBlock)sender).Name;
// Get TextBlock by name
TextBlock standTextBlockFromName = (TextBlock)this.FindName(stand);
standTextBlockFromName.Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255));
}
This question already has answers here:
MouseHover and MouseLeave don't work when the control is invisible
(4 answers)
Closed 3 years ago.
I have this TextBox that is invisible by default. Its location is lower left corner of the window/form. When I move my mouse to the lower left of the form, I want the TextBox to show up, so I can type some things in it. But, as soon as I move my mouse away from the TextBox, it should become invisible again.
I have tried the following.
private void magicTextBox_MouseEnter(object sender, EventArgs e)
{
magicTextBox.Visible = true;
}
private void magicTextBox_MouseLeave(object sender, EventArgs e)
{
magicTextBox.Visible = false;
}
The problem is, once it becomes invisible, it doesn't become visible again when you hover in the lower left corner.
This issue was brought up and answered here.
You need to add MouseMove event on the Form.
private void Form_MouseMove(object sender, MouseEventArgs e) {
if (magicTextBox.Bounds.Contains(e.Location) && !magicTextBox.Visible) {
//Do something...
}
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want that if i click on an image it gives a visual effect like whirl effect or glow effect or anything else on specific part around the point where i clicked with the mouse. for example if anyone has used the picture password of UC browser of windows phone exactly the same i want.
I have not tried anything because i have no knowledge of animation and graphics hence i haven't tried anything.
public void start()
{
messagebox.show("i haven't tried anything yet no knowledge of animation");
}
This code is nothing but i wrote it because i was not able to post the question.
In Winforms you could write code like this:
int AnimationCounter = 0;
Point AnimationCenter = Point.Empty;
Timer AnimationTimer = new Timer();
private void pictureBox1 _MouseClick(object sender, MouseEventArgs e)
{
AnimationCenter = e.Location;
AnimationTimer.Interval = 20;
AnimationTimer.Start();
}
void AnimationTimer_Tick(object sender, EventArgs e)
{
if (AnimationCounter > 15)
{
AnimationTimer.Stop();
AnimationCounter = 0;
pictureBox1.Invalidate();
}
else
{
AnimationCounter += 1;
pictureBox1.Invalidate();
}
}
private void pictureBox1 _Paint(object sender, PaintEventArgs e)
{
if (AnimationCounter > 0)
{
int ac = AnimationCounter / 2;
e.Graphics.DrawEllipse(Pens.Orange, AnimationCenter.X - ac,
AnimationCenter.Y - ac, ac * 2, ac * 2);
}
}
Don't forget to hook up the Paint and MouseClick event and also the AnimationTimer_Tick event.!
The result will draw a growing circle at the spot you click on which will disappear after ca. 10 * 20 ms..
Update: The first version suffered from repeatedly hooking up the Tick event. This one is better tested ;-)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am trying to override the paint event of a Windows Form, however all painting I do to the Form stays, even after I've Invalidate() and Update() the Form.
I am using a Timer to Invalidate() and Update() the Form, which causes the OnPaint() to be called
Here is the code:
// In the constructor the timer is created and enabled
private void UpdaterElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
WIDGET.Invalidate();
WIDGET.Update();
}
private void WIDGET_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
String text = DateTime.Now.ToString("hh:mm:ss tt");
e.Graphics.DrawString(text, new Font("Arial", 32), Brushes.Black, new Point(0, 0));
}
It's not supposed to clear the form (though getting paint events triggered by covering your window should do the job anyway). Simply clear it yourself if you need to:
e.Graphics.Clear(/* insert your color here */);
You have to clear graphics with some color which should be considered as transparent and then simply setup transparency key.
e.Graphics.Clear(Color.Purple);
this.TransparencyKey = Color.Purple;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have set of dynamically created checkboxes on a panel and also have implemented ContextMenuStrip on all checkboxes.
I am unable to detect that which control currently displays the shortcut menu defined in the ContextMenuStrip.
I have got the answer.
private void MenuViewDetails_Click(object sender, EventArgs e)
{
// Try to cast the sender to a MenuItem
MenuItem menuItem = sender as MenuItem;
if (menuItem != null)
{
// Retrieve the ContextMenu that contains this MenuItem
ContextMenu menu = menuItem.GetContextMenu();
// Get the control that is displaying this context menu
Control sourceControl = menu.SourceControl;
}
}
Use the SourceControl() property.
With a ContextMenu:
private void menuItem1_Click(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)contextMenu1.SourceControl;
Console.WriteLine(cb.Name);
}
With a ContextMenuStrip:
private void renameToolStripMenuItem_Click(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)contextMenuStrip1.SourceControl;
Console.WriteLine(cb.Name);
}