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 ;-)
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 2 years ago.
Improve this question
On this code I am starting and stopping random sampling based on a fixed sampling time.
When I clicked stop sampling, timers stops correctly.
But when I start back again, the times do not start correctly.
could you please help to check what is wrong here?
public partial class MainWindow : Window
{
public float samplingTime = 10f;
double currentDateTime = 0.0;
DateTime dtEnd;
public bool running;
public MainWindow()
{
InitializeComponent();
timer1 start.code()
void timer_Tick(object sender, EventArgs e)
{
dtEnd = DateTime.Now.AddSeconds(samplingTime);
someCode();
}
}
private void startSample_Click(object sender, RoutedEventArgs e)
{
timer2 start code()
void windowtimer_Tick(object sender, EventArgs e)
{
currentDateTime = (dtEnd - DateTime.Now).TotalSeconds;
if (currentDateTime < 0.1 && running == true)
{
code();
}
}
}
private void stopSample_Click(object sender, RoutedEventArgs e)
{
timer.Stop();
windowTimer.Stop();
}
You are adding the Tick handler multiple times:
windowTimer.Tick += windowtimer_Tick;
is executed every time you start, but you don't unhook it. Probably you should set the handler elsewhere (in the designer maybe).
Or you can add:
windowTimer.Tick -= windowtimer_Tick;
to the Stop handle
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 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.
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 does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to build a simple C# Windows Form Application that gathers user's keystrokes data.
Basically, the user needs to type in a word with length 10. I want to record each key's holding time, keydown to keydown time and keyup and keydown for adjacent keystrokes (so there are 10 + 9 + 9 = 28 measurements).
Could anyone tell me how to capture this information using text box events?
Thanks in advance
You can handle KeyUp and KeyDown events on your TextBox. You can get current timestamp using DateTime.Now.
Store your last KeyUp and KeyDown events time and add measurements like this:
private DateTime? keyUpTime = null;
private DateTime? keyDownTime = null;
private List<double> keyDownKeyUpMeasurements = new List<double>();
private List<double> keyDownKeyDownMeasurements = new List<double>();
private List<double> keyUpKeyDownMeasurements = new List<double>();
private void textBox_KeyDown(object sender, KeyEventArgs e)
{
DateTime prevKeyDownTime = keyDownTime;
keyDownTime = DateTime.Now;
if (prevKeyDownTime != null)
{
keyDownKeyDownMeasurements
.Add(keyDownTime.Subtract(prevKeyDownTime).TotalMilliseconds);
}
if (keyUpTime != null)
{
keyUpKeyDownMeasurements
.Add(keyDownTime.Subtract(keyUpTime).TotalMilliseconds);
}
}
private void textBox_KeyUp(object sender, KeyEventArgs e)
{
keyUpTime = DateTime.Now;
keyDownKeyUpMeasurements
.Add(keyUpTime.Subtract(keyDownTime).TotalMilliseconds);
}