Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) TextBox controls the length and width of the overlayNode through the mouse wheel (Read 3569 times)
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
TextBox controls the length and width of the overlayNode through the mouse wheel
Mar 31st, 2020 at 7:25am
Print Post  
Hey, Lyubo. Smiley

The two TextBoxes are bound to the length and width of the overlayNode, so that the length and width of the overlayNode are displayed in the TextBox in real-time. When the cursor is displayed in the TextBox, it responds to the mouse wheel event, and the value of the TextBox is increased or decreased by the wheel to change the length and width of the overlayNode.
  

3_31_5.png ( 311 KB | 138 Downloads )
3_31_5.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: TextBox controls the length and width of the overlayNode through the mouse wheel
Reply #1 - Mar 31st, 2020 at 10:29am
Print Post  
private void RibbonButton_Click(object sender, RoutedEventArgs e)
{
if (overlayNode == null)
return;

double x = overlayNode.Bounds.X,
y = overlayNode.Bounds.Y;
// Get the new values from the 2 text boxes
double newValue;
if (double.TryParse(textBoxW.Text, out newValue))
x = newValue;
if (double.TryParse(textBoxH.Text, out newValue))
y = newValue;
var newBounds = new Rect(imageNode.Bounds.Right - x, imageNode.Bounds.Bottom - y, x, y);
// Change the node's position / dimensions
overlayNode.SetBounds(newBounds, true, true);
imageNode.InvalidateVisual();
}

I use this method RibbonButton_Click (object sender, RoutedEventArgs e) to achieve the value of the two TextBox changes the length and width of the overlayNode. But now I want to extend the two TextBoxes to control the length and width of the overlayNode. The implementation functions are as follows: one: displaying the length and width values ​​of the overlayNode in two TextBoxes in real time; two: when the cursor is displayed in the TextBox, the TextBox responds to the mouse wheel event and changes the length and width values ​​of the overlayNode by scrolling with the wheel. How can I achieve this?
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: TextBox controls the length and width of the overlayNode through the mouse wheel
Reply #2 - Mar 31st, 2020 at 1:03pm
Print Post  
Hi Lyubo, I have been waiting for your answer Smiley
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: TextBox controls the length and width of the overlayNode through the mouse wheel
Reply #3 - Apr 1st, 2020 at 5:18am
Print Post  
Subsribe to the TextBox.MouseWheen event and use that handler for the width TextBox:
Code
Select All
		private void textBoxW_MouseWheel(object sender, MouseWheelEventArgs e)
		{
			if (overlayNode == null)
				return;

                        // this value is used only for demonstration, adjust as per your requirements
			var delta = e.Delta > 0 ? 10 : -10;

			var newBounds = new Rect(overlayNode.Bounds.X - delta, overlayNode.Bounds.Y, overlayNode.Bounds.Width + delta, overlayNode.Bounds.Height);
			overlayNode.SetBounds(newBounds, true, true);
			imageNode.InvalidateVisual();

			textBoxW.Text = overlayNode.Bounds.Width.ToString();
		}
 



Attach another handler to the height TextBox with similar logic to change the node's height.

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: TextBox controls the length and width of the overlayNode through the mouse wheel
Reply #4 - Apr 1st, 2020 at 6:33am
Print Post  
Thanks a lot, Lyubo Smiley

private void textBoxW_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (overlayNode == null)
                return;

            // this value is used only for demonstration, adjust as per your requirements
            var delta = e.Delta > 0 ? 10 : -10;

            var newBounds = new Rect(overlayNode.Bounds.X - delta, overlayNode.Bounds.Y, overlayNode.Bounds.Width + delta, overlayNode.Bounds.Height);
            overlayNode.SetBounds(newBounds, true, true);
            imageNode.InvalidateVisual();

            textBoxW.Text = overlayNode.Bounds.Width.ToString();
        }

I currently use the mouse to scroll the textBoxW, but it doesn't respond to this method: textBoxW_MouseWheel (object sender, MouseWheelEventArgs e). It just responds to the menu page up or page down. What changes do I need to make?
  

4_1_1.png ( 342 KB | 126 Downloads )
4_1_1.png
4_1_2.png ( 288 KB | 134 Downloads )
4_1_2.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: TextBox controls the length and width of the overlayNode through the mouse wheel
Reply #5 - Apr 1st, 2020 at 8:45am
Print Post  
Hey, Lyubo. Smiley
Because these two TextBoxes are nested inside the Ribbon menu control, the MouseWheel event currently only responds to the Ribbon. How can I implement a response to the MouseWheel event of the TextBox without affecting the MouseWheel event of the Ribbon. How can I achieve this? Is there any sample code?
  

4_1_3.png ( 247 KB | 141 Downloads )
4_1_3.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: TextBox controls the length and width of the overlayNode through the mouse wheel
Reply #6 - Apr 1st, 2020 at 10:40am
Print Post  
Hello, Lyubo, Smiley I urgently need your help, please guide me to complete this work.
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: TextBox controls the length and width of the overlayNode through the mouse wheel
Reply #7 - Apr 2nd, 2020 at 4:52am
Print Post  
Hi,

Handle PreviewMouseWheel instead of the MouseWheel evnt and set e.Handled to true.

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: TextBox controls the length and width of the overlayNode through the mouse wheel
Reply #8 - Apr 2nd, 2020 at 6:14am
Print Post  
Thanks a lot, Lyubo Smiley
I tried to use this method PreviewMouseWheel, and set e.Handled = true; but there is no response method PreviewMouseWheel, I do not know where to set it in place, what is missing? Please tell me how to modify it?
xaml:
<StackPanel>
                                <DockPanel>
                                    <Label Content="PCB长度"/>
                                    <RibbonTextBox Name="textBoxW" PreviewTextInput="tb_PreviewTextInput" InputMethod.IsInputMethodEnabled="False" PreviewMouseWheel="numberWheelchange" />
                                </DockPanel>
                                <DockPanel>
                                    <Label Content="PCB宽度"/>
                                    <RibbonTextBox Name="textBoxH" PreviewTextInput="tb_PreviewTextInput" InputMethod.IsInputMethodEnabled="False" PreviewMouseWheel="numberWheelchange" />
                                </DockPanel>
                                <DockPanel>
                                    <Label Content="轨道宽度"/>
                                    <RibbonTextBox/>
                                </DockPanel>
                            </StackPanel>

cs:
private void numberWheelchange(object sender, MouseWheelEventArgs e)
        {
            if (textBoxW.IsSelectionActive)
            {
                if (textBoxW.Text != null)
                {
                    if (overlayNode == null)
                        return;

                    // this value is used only for demonstration, adjust as per your requirements
                    var delta = e.Delta > 0 ? 10 : -10;

                    var newBounds = new Rect(overlayNode.Bounds.X - delta, overlayNode.Bounds.Y, overlayNode.Bounds.Width + delta, overlayNode.Bounds.Height);
                    overlayNode.SetBounds(newBounds, true, true);
                    imageNode.InvalidateVisual();

                    textBoxW.Text = overlayNode.Bounds.Width.ToString();
                }
            }
            if (textBoxH.IsSelectionActive)
            {
                if (textBoxH.Text != null)
                {
                    if (overlayNode == null)
                        return;

                    // this value is used only for demonstration, adjust as per your requirements
                    var delta = e.Delta > 0 ? 10 : -10;

                    var newBounds = new Rect(overlayNode.Bounds.X, overlayNode.Bounds.Y - delta, overlayNode.Bounds.Width, overlayNode.Bounds.Height + delta);
                    overlayNode.SetBounds(newBounds, true, true);
                    imageNode.InvalidateVisual();

                    textBoxW.Text = overlayNode.Bounds.Width.ToString();
                }
            }
            e.Handled = true;
        }
  

4_2.png ( 498 KB | 131 Downloads )
4_2.png
4_2_1.png ( 202 KB | 141 Downloads )
4_2_1.png
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: TextBox controls the length and width of the overlayNode through the mouse wheel
Reply #9 - Apr 2nd, 2020 at 7:45am
Print Post  
Hi,

The code you posted above works in my test. There must be something else preventing you from achieving the behavior you want.

Rgards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: TextBox controls the length and width of the overlayNode through the mouse wheel
Reply #10 - Apr 2nd, 2020 at 7:49am
Print Post  
Thank you very much, Lyubo. Smiley It must be the MouseWheel of the Ribbon control that overwrites the MouseWheel I set.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint