how to navigate adorner when click button - vb.net

I create a sample of adorner to inform client the use usage of each component.
What i want to ask is, how do i move the control/adorner to other component.
in the picture when i click the help button,it show the adorner. how do i move the adorner to the textedit2 purple square. the adorner using usercontrol.
this is the form1 code
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AdornerUIManager1.ShowGuides = DevExpress.Utils.DefaultBoolean.True
End Sub
Private Sub AdornerUIManager1_QueryGuideFlyoutControl(sender As Object, e As DevExpress.Utils.VisualEffects.QueryGuideFlyoutControlEventArgs) Handles AdornerUIManager1.QueryGuideFlyoutControl
If e.SelectedElement.TargetElement Is Button1 Then
e.Control = New LabelControl() With {
.AllowHtmlString = True,
.Width = 350,
.AutoSizeMode = LabelAutoSizeMode.Vertical,
.Padding = New Padding(20),
.Text = "<b>Navigation Bar</b><br>" & "A side navigation control that supports integration with Office Navigation Bar<br><br>" & "Shows navigation options for your currently selected module"}
End If
If e.SelectedElement.TargetElement Is TextEdit1 Then
Dim x As New UserControl1
x.Label1.Text = "xxXXXxx"
x.WindowsUIButtonPanel1.Buttons(0).Properties.Checked = True
e.Control = x
End If
End Sub
this is the usercontrol code
Public Class UserControl1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim x As Form1
x.AdornerUIManager1.Elements(0).TargetElement = x.TextEdit3
End Sub
End Class
when i try to click, it got error

Related

How to autoscroll panel or picturebox in MouseMove event in VB:NET

I'm trying to autoscroll panel with an image using mousemove event simulating a dynamic zoom.
I found this example Pan/scroll an image in VB.NET and this Scroll panel based on mouse position in VB.NET but I realized that the user have to click on the image to drag it, so I tried to modify the code but doesn't work
This is what I tried:
Private m_PanStartPoint As New Point
Private Sub PictureBox2_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseMove
Dim DeltaX As Integer = (m_PanStartPoint.X - e.X)
Dim DeltaY As Integer = (m_PanStartPoint.Y - e.Y)
Panel1.AutoScrollPosition = New Point((DeltaX - Panel1.AutoScrollPosition.X), (DeltaY - Panel1.AutoScrollPosition.Y))
End Sub
Private Sub PictureBox2_MouseEnter(sender As Object, e As EventArgs) Handles PictureBox2.MouseEnter
PictureBox2.SizeMode = PictureBoxSizeMode.AutoSize
m_PanStartPoint = New Point(MousePosition)
End Sub
Private Sub PictureBox2_MouseLeave(sender As Object, e As EventArgs) Handles PictureBox2.MouseLeave
PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
I also tried adding the event MouseHover:
Private Sub PictureBox2_MouseHover(sender As Object, e As EventArgs) Handles PictureBox2.MouseHover
m_PanStartPoint = New Point(MousePosition)
End Sub
if there is a way to do it without a panel, it would be better.
'The VB/XAML code below implements left mouse button click+hold scrolling and also works with touch screens. When using this code, put your frame/grid/image within a scrollviewer as shown below:
'XAML
<ScrollViewer x:Name="ScrollViewerObject" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Hidden" ScrollViewer.CanContentScroll="False" PreviewMouseDown="Part_ScrollViewer_PreviewMouseDown" PreviewMouseMove="Part_ScrollViewer_PreviewMouseMove">
<Frame x:Name="PartViewer" NavigationUIVisibility="Hidden"/>
</ScrollViewer>
'VB
Dim LastScrollPos As Double = 0
Dim MouseStartPos AS Double = 0
Private Sub ScrollViewerObject_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs)
Dim position As Point = Mouse.GetPosition(ScrollViewerObject)
ScrollViewerObject.UpdateLayout()
LastScrollPos = ScrollViewerObject.ContentVerticalOffset
MouseStartPos = position.Y
End Sub
Private Sub ScrollViewerObject_PreviewMouseMove(sender As Object, e As MouseEventArgs)
If Mouse.LeftButton = MouseButtonState.Pressed Then
Dim position As Point = Mouse.GetPosition(ScrollViewerObject)
ScrollViewerObject.ScrollToVerticalOffset(LastScrollPos + (position.Y - MouseStartPos))
End If
End Sub

Remove Or Delete the Rectangle drawn on the PictureBox

I am currently solving a bug that will remove the created rectangle on the PictureBox. The problem is that when I click an Item on the PictureBox and Resize the windows form, the rectangle does not move on with the item selected. This is the code creating the rectangle:
Private Sub paintRectangle(pictBox As System.Windows.Forms.PictureBox, pic As Image)
If pic Is Nothing Then Exit Sub
pictBox.Image = pic
If m_rect_x = -1 And m_rect_y = -1 Then
Return
End If
Dim graphic As System.Drawing.Graphics
Dim redselpen As System.Drawing.Pen
Dim yNegative As Integer = 3
redselpen = New System.Drawing.Pen(Color.Blue)
redselpen.DashStyle = Drawing2D.DashStyle.DashDot
If pictBox.Image IsNot Nothing Then
graphic = System.Drawing.Graphics.FromImage(pictBox.Image)
graphic.DrawRectangle(redselpen, m_rect_x, m_rect_y - yNegative, SystemConfig.iRectWidth, SystemConfig.iRectHeight + 2)
pictBox.Image = pictBox.Image
End If
End Sub
After Resizing the Form, I want to remove the create a rectangle on the PictureBox.
I tried this solution but the Rectangle is still in the PictureBox.
How to remove all the drawn rectangles on the picture box? (Not on the image)
But it does not work, the rectangle is still in the picturebox.
Here's a simple example showing the Paint() event of a PictureBox being used to draw a rectangle that can be moved and turned on/off:
Public Class Form1
Private yNegative As Integer = 3
Private pt As New Nullable(Of Point)
Private drawRectangle As Boolean = False
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
If drawRectangle AndAlso pt.HasValue Then
Using redselpen As New System.Drawing.Pen(Color.Blue)
redselpen.DashStyle = Drawing2D.DashStyle.DashDot
e.Graphics.DrawRectangle(redselpen, pt.Value.X, pt.Value.Y - yNegative, SystemConfig.iRectWidth, SystemConfig.iRectHeight + 2)
End Using
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
pt = New Point(25, 25)
drawRectangle = True
PictureBox1.Invalidate()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
drawRectangle = Not drawRectangle ' toggle the rectangle on/off
PictureBox1.Invalidate()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
pt = New Point(150, 25)
drawRectangle = True
PictureBox1.Invalidate()
End Sub
End Class

Can not change the value of a combobox in an user control from another form

I have an user control in Autocad that makes drawings based on certain criteria.
From this user control, another form can be opened which is used to fill in specific data.
When i try to automatically change the Combobox in the User Control with data from the Form, it gives the error:
Reference to a non-shared member requires an object reference.
Now I have looked this up on the internet, but I can not seem to apply the solutions given.
My situation is as follows:
Partial Public Class Partial Public Class User_Control
Private Form1 As New Form_Something
private sub button1_click(sender As Object, e As EventArgs) Handles button1.Click
Form1.show()
End sub
End Class
This User Control has got a Combobox, lets name it Combobox1. Now when i change a value on Form_Something, Combobox1 must change as well.
So I've got the following code in Form1:
Partial public class Form_Something
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles BT_Apply.Click
User_Control.Combobox1.text = "Apples"
End sub
End class
This gives the mentioned error.
Can someone please help me resolve this issue, because I'd like to do this with multiple comboboxes/labels etc.
To show you more intuitively, I changed the BorderStyle of UserControl1 here. You can change or comment it as needed.
I have commented on some key parts of the code, please let me know if you are still confused.
If my post helps to resolve your issue, please click the "Mark as Answer" of that post. By marking a post as Answered or Helpful, you help others find the answer faster.
The results are as follows:
My code are as follows:
1.Form1 code:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs)
MyUserControl.ComboBox1.Text = "Apples"
End Sub
End Class
2.UserControl1 code:
Public Class UserControl1
Private Sub UserControl1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Text = "Apple"
Me.BorderStyle = BorderStyle.Fixed3D
End Sub
Dim myForm As Form
Dim btn As Button
Dim txtbox As TextBox
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
myForm = New Form With {.Text = "myForm"}
btn = New Button With {.Text = "Save", .Height = 30, .Width = 60, .Top = 100, .Left = 150}
txtbox = New TextBox With {.Text = "", .Height = 20, .Width = 100, .Top = 100, .Left = 20}
myForm.Controls.Add(btn)
myForm.Controls.Add(txtbox)
myForm.Show() 'Open dialog in modeless window
AddHandler btn.Click, AddressOf Btn_Click
End Sub
Sub Btn_Click(sender As System.Object, e As System.EventArgs)
Me.ComboBox1.Text = txtbox.Text 'This step is important!
myForm.Close()
End Sub
End Class

Handling multiple dialogs in VB.net

I'm a little confused as to how I'm supposed to handle a chain of dialogs in my VB.net application. For example I have 4 forms, each one has a simple label and is subsequently called from the previous one as a dialog.
First form:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim frm As New Form2
Form2.ShowDialog(Me)
End Sub
End Class
Second form:
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim frm As New Form3
frm.ShowDialog(Me)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim cls As New LabelFlash
cls.Flash()
End Sub
End Class
Third form:
Public Class Form3
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim frm As New Form4
frm.ShowDialog(Me)
Me.DialogResult = Windows.Forms.DialogResult.OK
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim cls As New LabelFlash
cls.Flash()
End Sub
End Class
Fourth form:
Public Class Form4
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cls As New LabelFlash
cls.Flash()
End Sub
End Class
And the class they all refer to just toggles the visibility of a label on each form:
Public Class LabelFlash
Sub Flash()
If Form1.Label1.Visible = False Then
Form1.Label1.Visible = True
Else
Form1.Label1.Visible = False
End If
If Form2.Label1.Visible = False Then
Form2.Label1.Visible = True
Else
Form2.Label1.Visible = False
End If
If Form3.Label1.Visible = False Then
Form3.Label1.Visible = True
Else
Form3.Label1.Visible = False
End If
If Form4.Label1.Visible = False Then
Form4.Label1.Visible = True
Else
Form4.Label1.Visible = False
End If
End Sub
End Class
Here's my question. When I only have forms 1 and 2 open and I click the button, the label toggle works fine. However, when I get to the third (and fourth) windows only the labels on form 1 and form 2 will toggle and not the third and fourth ones. Additionally, when I close the fourth window it also closes the third at the same time.
I'm sure there's something I'm missing here. Thanks for any help.

How to Dock to StatusBar

I have Form with StatusBar on it. On StatusBar there are ToolStripStatusLabel1 and ToolStripProgressBar1. Normaly, ToolStripProgressBar is not visible.
But when I start file copying ToolStripStatusLabel1 becames invisible and ToolStripProgressBar becames visible.
like this:
ToolStripStatusLabel1.Visible = False
ToolStripProgressBar1.Visible = True
Problem is that in this condition I cant get that ProgressBar take all the space of StatusBar not with increasing it's width nor with setting it's Dock property to .Fill.
ToolStripStatusLabel1.Visible = False
ToolStripStatusLabel1.Width = 0
ToolStripProgressBar1.Dock = DockStyle.Fill
Is it possible to get ToolStripProgressBar1 to take full Width of StatusBar in described situation?
The ToolStripProgressBar is quite limited and can't do what you want.
An alternative is to make a regular ProgressBar take the place of your entire StatusStrip:
Public Class Form1
Private PB As New ProgressBar
Private ShowProgress As Boolean = False
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ShowProgressBar(True)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ShowProgressBar(False)
End Sub
Private Sub ShowProgressBar(ByVal Visible As Boolean)
ShowProgress = Visible
If ShowProgress Then
Dim rc As Rectangle = StatusStrip1.RectangleToScreen(StatusStrip1.ClientRectangle)
PB.Bounds = Me.RectangleToClient(rc)
PB.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Bottom
Me.Controls.Add(PB)
PB.BringToFront()
Else
Me.Controls.Remove(PB)
End If
End Sub
End Class