|
i am developing one designing tool..in this i need to implement ruler line.. How can i achieve this.. Please Help me.. Thanks | | dilipkumarmdk Thursday, April 23, 2009 8:15 AM | To demonstrate my idea, I wrote some code for your reference here. I draw all elements in the paint method of the userControl. So you may see the UI flashes some time. So you can consider draw the scale in a picture, and only draw the two short lines which moves according to the mouse movement.
Public Class RulerLineVB
Private mouseCurrentPoisiton As Point
Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
AddHandler Me.Paint, AddressOf RulerLineControl_Paint
AddHandler Me.MouseMove, AddressOf RulerLineControl_MouseMove
End Sub
Private Sub RulerLineControl_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
Me.mouseCurrentPoisiton = New Point(e.X, e.Y)
MyBase.Invalidate()
End Sub
Private Sub RulerLineControl_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
Dim num As String
Dim g As Graphics = e.Graphics
Dim horzontalRec As New Rectangle(20, 0, (MyBase.Width - &H16), 20)
Dim verticalRec As New Rectangle(0, 20, 20, (MyBase.Height - &H16))
g.DrawRectangle(Pens.Black, horzontalRec)
g.DrawRectangle(Pens.Black, verticalRec)
Dim countX As Integer = 1
Dim beginX As Integer = 20
Do While (beginX < MyBase.Width)
If ((countX Mod 10) = 0) Then
num = (countX / 10).ToString()
g.DrawString(num, New Font("Arial", 8.0!), Brushes.Black, New Point(beginX, 0))
Else
g.DrawLine(Pens.Black, New Point(beginX, 5), New Point(beginX, 10))
End If
countX += 1
beginX = (beginX + 10)
Loop
Dim CountY As Integer = 1
Dim beginY As Integer = 20
Do While (beginY < MyBase.Height)
If ((CountY Mod 10) = 0) Then
num = (CountY / 10).ToString
Dim format As New StringFormat(StringFormatFlags.DirectionVertical)
g.DrawString(num, New Font("Arial", 8.0!), Brushes.Black, New Point(0, beginY), format)
Else
g.DrawLine(Pens.Black, New Point(5, beginY), New Point(10, beginY))
End If
CountY += 1
beginY = (beginY + 10)
Loop
g.DrawLine(Pens.Red, New Point(Me.mouseCurrentPoisiton.X, 0), New Point(Me.mouseCurrentPoisiton.X, 20))
g.DrawLine(Pens.Red, New Point(0, Me.mouseCurrentPoisiton.Y), New Point(20, Me.mouseCurrentPoisiton.Y))
End Sub
End Class
Here you can download my test application(Visual Studio 2008 solution) here , this is for if you have difficulty in testing the code. If you have further problem, please feel free to let me know. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byBruce.ZhouMSFT, ModeratorWednesday, April 29, 2009 9:27 AM
-
| | Bruce.Zhou Monday, April 27, 2009 9:26 AM | I've downloaded the software and used it for a while. I think you are focusing on how to implement the ruler lines, right? If so, I think you can create a usercontrol. In the Paint event of the user control, you can first draw the static elements, such as the scale of the ruler line. We can see when the mouse is moving, there are two short lines moving in both the vertical and horizontal ruler lines. To achieve this, we can handler the mouse move event of the UserControl, and draw the short lines with the current poistion of the mouse. Best regards, Bruce Zhou Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byBruce.ZhouMSFT, ModeratorWednesday, April 29, 2009 9:27 AM
-
| | Bruce.Zhou Monday, April 27, 2009 8:18 AM | You're welcome. I can see when dragging outside, the rubber band rectangle can't be redrawn properly sometimes. Basically, I think you can try to restrict the rubber selection only in the panel. Because I think it isn't useful to select outside the panel since all the controls needs to be selected are inside the panel. Please also let me know your ideas, try to find a way to make the rectangle draw properly outside the panel, or restrict the rubber selection area. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer bydilipkumarmdk Friday, May 01, 2009 2:29 PM
-
| | Bruce.Zhou Friday, May 01, 2009 10:32 AM | Hi dilipkumarmdk, I'll never take Negative thinking on you as we are all experts on some subject, but not expert in all aspects. I've made a demo project which implements the ruler lines using background images. Please download my changed project here . Note that it's finsihed under Visual Studio 2008. Let me know if you have problems. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer bydilipkumarmdk Tuesday, May 05, 2009 5:46 AM
-
| | Bruce.Zhou Sunday, May 03, 2009 1:31 PM | Hi dilipkumarmdk, Would please explain your requirement in detail? I'm not sure with it. Best regards, Bruce Zhou Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Friday, April 24, 2009 11:48 AM | Hi..Thanks for reply.. Actually my requirement is i am developing one Design Application like our Dotnet design window in this i will do controls drag and drop..controls deletion,moving all the functionalities are there. so in this i want to add Ruler line like our (MS-OFFICE Ruler) Horizentally and vertically.. I think now you understand my Question.. Please if you know this please help me.. Thanks
| | dilipkumarmdk Monday, April 27, 2009 4:13 AM | Thanks for your clarification. I think you can host a designer on your form. So that you can get all the functionalities that Visual Studio designer has. Here's the sample code provided by Zhi-Xin ye in a solved thread . To learn more how to host designer, you can refer to this blog . If you have difficulty in implmenting them or any further problem, please feel free to let me know. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Monday, April 27, 2009 5:18 AM | Hi Bruce.. I think your not understand my question.. So please if u don't mine u can download Formatta Designer 7.0 software..In that there is Ruler Line(Horizontally and vertically) like that i need to implement in my project. please help me..I am expected you know something about this topic.. Help me.. Thanks..
| | dilipkumarmdk Monday, April 27, 2009 8:01 AM | I've downloaded the software and used it for a while. I think you are focusing on how to implement the ruler lines, right? If so, I think you can create a usercontrol. In the Paint event of the user control, you can first draw the static elements, such as the scale of the ruler line. We can see when the mouse is moving, there are two short lines moving in both the vertical and horizontal ruler lines. To achieve this, we can handler the mouse move event of the UserControl, and draw the short lines with the current poistion of the mouse. Best regards, Bruce Zhou Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byBruce.ZhouMSFT, ModeratorWednesday, April 29, 2009 9:27 AM
-
| | Bruce.Zhou Monday, April 27, 2009 8:18 AM | To demonstrate my idea, I wrote some code for your reference here. I draw all elements in the paint method of the userControl. So you may see the UI flashes some time. So you can consider draw the scale in a picture, and only draw the two short lines which moves according to the mouse movement.
Public Class RulerLineVB
Private mouseCurrentPoisiton As Point
Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
AddHandler Me.Paint, AddressOf RulerLineControl_Paint
AddHandler Me.MouseMove, AddressOf RulerLineControl_MouseMove
End Sub
Private Sub RulerLineControl_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
Me.mouseCurrentPoisiton = New Point(e.X, e.Y)
MyBase.Invalidate()
End Sub
Private Sub RulerLineControl_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
Dim num As String
Dim g As Graphics = e.Graphics
Dim horzontalRec As New Rectangle(20, 0, (MyBase.Width - &H16), 20)
Dim verticalRec As New Rectangle(0, 20, 20, (MyBase.Height - &H16))
g.DrawRectangle(Pens.Black, horzontalRec)
g.DrawRectangle(Pens.Black, verticalRec)
Dim countX As Integer = 1
Dim beginX As Integer = 20
Do While (beginX < MyBase.Width)
If ((countX Mod 10) = 0) Then
num = (countX / 10).ToString()
g.DrawString(num, New Font("Arial", 8.0!), Brushes.Black, New Point(beginX, 0))
Else
g.DrawLine(Pens.Black, New Point(beginX, 5), New Point(beginX, 10))
End If
countX += 1
beginX = (beginX + 10)
Loop
Dim CountY As Integer = 1
Dim beginY As Integer = 20
Do While (beginY < MyBase.Height)
If ((CountY Mod 10) = 0) Then
num = (CountY / 10).ToString
Dim format As New StringFormat(StringFormatFlags.DirectionVertical)
g.DrawString(num, New Font("Arial", 8.0!), Brushes.Black, New Point(0, beginY), format)
Else
g.DrawLine(Pens.Black, New Point(5, beginY), New Point(10, beginY))
End If
CountY += 1
beginY = (beginY + 10)
Loop
g.DrawLine(Pens.Red, New Point(Me.mouseCurrentPoisiton.X, 0), New Point(Me.mouseCurrentPoisiton.X, 20))
g.DrawLine(Pens.Red, New Point(0, Me.mouseCurrentPoisiton.Y), New Point(20, Me.mouseCurrentPoisiton.Y))
End Sub
End Class
Here you can download my test application(Visual Studio 2008 solution) here , this is for if you have difficulty in testing the code. If you have further problem, please feel free to let me know. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byBruce.ZhouMSFT, ModeratorWednesday, April 29, 2009 9:27 AM
-
| | Bruce.Zhou Monday, April 27, 2009 9:26 AM | Hi dilipkumarmdk, I'd like to know which problem you are facing now. Did you test my solution? I've also tried your application. Is the Canvas a panel control? If so, you can handle the Paint event as I did. and paste the code there. If you meet any problem, please feel free to let me know. Best regards, Bruce Zhou Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Thursday, April 30, 2009 5:53 AM |
i draw the Rubber band selection on panel in my panel having some shapecontrols(Visual basic POWERPACK Controls)..
so when i draw Rubberband Selection on panel These Controls are shaking(Something effect) is come..
I don't why it's working like this..
Please Before You check my code Take Some ShapeControls on panel..
Please check my code..
Thanks & Regards..
Public Class Form2
Private m_ActiveControl As Point
Private m_CurrentPoint As Point
Private Loc_x As Integer
Private Loc_y As Integer
Private r As Rectangle
Private ileft As Integer
Private itop As Integer
Private iwidth As Integer
Private iheight As Integer
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
m_ActiveControl.X = e.X
m_ActiveControl.Y = e.Y
m_CurrentPoint = m_ActiveControl
End Sub
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
If e.Button = MouseButtons.Left Then
m_CurrentPoint.X = e.X
m_CurrentPoint.Y = e.Y
Panel1.Invalidate(True) '.Invalidate()
End If
End Sub
Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
m_ActiveControl.X = 0
m_ActiveControl.Y = 0
m_CurrentPoint = m_ActiveControl
Panel1.Invalidate(True)
End Sub
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
ileft = Math.Min(m_ActiveControl.X, m_CurrentPoint.X) ' Drawing Rubberband on Canvas
iwidth = Math.Abs(m_ActiveControl.X - m_CurrentPoint.X)
itop = Math.Min(m_ActiveControl.Y, m_CurrentPoint.Y)
iheight = Math.Abs(m_ActiveControl.Y - m_CurrentPoint.Y)
Dim r As New Rectangle(ileft, itop, iwidth, iheight)
Dim p As New Pen(Color.Black)
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
e.Graphics.DrawRectangle(p, r)
End Sub
End Class
| | dilipkumarmdk Thursday, April 30, 2009 1:53 PM | When I port the code which achieve Rubber band selection, I don't see the shaking effect. You can download the changed project , and check out the effect. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Thursday, April 30, 2009 2:03 PM | Hi Bruce pleae Check Rubberband selection on panel ..It's not displayed in correct way ..means once compare with our .Net Designer .. Public Class Form12 Private bHaveMouse As Boolean Private button1 As Button Private ptLast As Point Private ptOriginal As Point Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown Me.bHaveMouse = True Me.ptOriginal.X = e.X Me.ptOriginal.Y = e.Y Me.ptLast.X = -1 Me.ptLast.Y = -1 End Sub Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove Dim ptCurrent As New Point(e.X, e.Y) If Me.bHaveMouse Then If (Me.ptLast.X <> -1) Then Me.MyDrawReversibleRectangle(Me.ptOriginal, Me.ptLast) End If Me.ptLast = ptCurrent Me.MyDrawReversibleRectangle(Me.ptOriginal, ptCurrent) End If End Sub Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp Me.bHaveMouse = False If (Me.ptLast.X <> -1) Then Dim ptCurrent As New Point(e.X, e.Y) Me.MyDrawReversibleRectangle(Me.ptOriginal, Me.ptLast) End If Me.ptLast.X = -1 Me.ptLast.Y = -1 Me.ptOriginal.X = -1 Me.ptOriginal.Y = -1 End Sub Private Sub MyDrawReversibleRectangle(ByVal p1 As Point, ByVal p2 As Point) Dim rc As New Rectangle p1 = MyBase.PointToScreen(p1) p2 = MyBase.PointToScreen(p2) If (p1.X < p2.X) Then rc.X = p1.X rc.Width = (p2.X - p1.X) Else rc.X = p2.X rc.Width = (p1.X - p2.X) End If If (p1.Y < p2.Y) Then rc.Y = p1.Y rc.Height = (p2.Y - p1.Y) Else rc.Y = p2.Y rc.Height = (p1.Y - p2.Y) End If ControlPaint.DrawReversibleFrame(rc, Color.Red, FrameStyle.Dashed) End Sub End Class
| | dilipkumarmdk Thursday, April 30, 2009 2:52 PM | Did you mean the control rectangle of the Selected controls should be displayed? If not, please clarify what difference you are refering to. Best regards, Bruce Zhou Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Thursday, April 30, 2009 3:55 PM | Hi bruce.. one thing i solved ..i am getting Rubber band selected area controls..but only the problem is when i take the shape controls from toolbox in my project and displaying on canvas it not displaying perfectly.. something Grabbing is come please help me.. thanks.. | | dilipkumarmdk Thursday, April 30, 2009 5:36 PM | Hi dilipkumarmdk, Sorry for the delay, I 've gone to sleep after my last post. I've donwloaded your project, and reproduced your problem this morning. To solve the problem, you can force a re-draw operation on or your child controls. Here's the changed code:
Public Sub MyPage_MouseUp(ByVal sender As System.Object, ByVal e As Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Try
ControlsSelections() 'For getting the Rubberband selected controls
Me.bHaveMouse = False
If (Me.ptLast.X <> -1) Then
Dim ptCurrent As New Point(e.X, e.Y)
Me.MyDrawReversibleRectangle(Me.ptOriginal, Me.ptLast)
End If
Me.ptLast.X = -1
Me.ptLast.Y = -1
Me.ptOriginal.X = -1
Me.ptOriginal.Y = -1
If fdragging Then '04-Mar-08
Call UpdateChanges()
fDrawShapes = False
End If
fdragging = False
Me.Invalidate(True)
Catch ex As Exception
MsgBox("Error at MyPage_MouseUp", MsgBoxStyle.Information, "Eform")
End Try
End Sub
The Line which is in bold font and Italic is what I add. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Friday, May 01, 2009 3:47 AM | Hi Bruce... Very Much thanks .. finally what happening is when Drawing Rubber band selection on panel ,in case draw out of the panel that drawing Rectangular will be displaying ..after mouse up of it's OK fine .. please check like this.. start ruuberband on panel and dragging to out of the panel Thanks & Regards
| | dilipkumarmdk Friday, May 01, 2009 9:23 AM | You're welcome. I can see when dragging outside, the rubber band rectangle can't be redrawn properly sometimes. Basically, I think you can try to restrict the rubber selection only in the panel. Because I think it isn't useful to select outside the panel since all the controls needs to be selected are inside the panel. Please also let me know your ideas, try to find a way to make the rectangle draw properly outside the panel, or restrict the rubber selection area. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer bydilipkumarmdk Friday, May 01, 2009 2:29 PM
-
| | Bruce.Zhou Friday, May 01, 2009 10:32 AM | Hi Bruce... Good Morning Before i told that One software FormattaDesigner 7.0 remember..in that having Ruler Line Horizontally and vertically same like that i can add in my application ..is it possible.. but before you sending it's a paint Ruler line..it's refreshing every time..but in that project it's different..they using some third perty Component ..how can i use this.. Please if you have idea please can you try in my application Please it's a big deal to me..you can solve this..please help Thanks & Regards Dilip.. | | dilipkumarmdk Saturday, May 02, 2009 3:50 AM | Good Morning.
Yes, it's possible. I notice that the ruler line I sent to you refreshing every time and cause flashing. But in my previous post, I've already told you, there's way to solve this.
Actually, we don't need to draw everything in the vertical and horizontal line in our code. We can make two pictures which hold the static elements, as you can do using image making tools,and make them as background images of two panels. The left thing is drawing only two short lines according to the mouse moving action.
You can try to implement as I suggest, if you meet problems, please let me know. Although I haven't tested, I think it's doable.
Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Saturday, May 02, 2009 4:57 AM | Hi Bruce.. Good Morning As you told it's ok fine..But implementation is something difficult to me.please solve my problem..it's Big deal to me.. Please can you try this one ..please Don't take Negative thinking on me..Because this is new things to me so please help me.. Thanks & Regards.. Dilip
| | dilipkumarmdk Sunday, May 03, 2009 3:45 AM | Hi dilipkumarmdk, I'll never take Negative thinking on you as we are all experts on some subject, but not expert in all aspects. I've made a demo project which implements the ruler lines using background images. Please download my changed project here . Note that it's finsihed under Visual Studio 2008. Let me know if you have problems. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer bydilipkumarmdk Tuesday, May 05, 2009 5:46 AM
-
| | Bruce.Zhou Sunday, May 03, 2009 1:31 PM | Hi Bruce.. How to add Background Image of panel at particular position in vb.net(Windows)..Is it possible.. Thanks & Regards Dilip
| | dilipkumarmdk Tuesday, May 05, 2009 5:49 AM | In my sample, I create two user controls, each of which has BackGroundImage property set. So in the calling code, we can addjust the location of the user controls. I think you can reuse the two user controls I've created, and change the background image as you wish. >How to add Background Image of panel at particular position in vb.net(Windows)..Is it possible.. I'm not sure what you mean. Did you want to set the location of the Background image in panel? If so, why do you want to do this? Best regards, Bruce Zhou Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Tuesday, May 05, 2009 7:51 AM | hi bruce.. before i am asking this is not related to Ruler line..this is separate question.. what i want is i want set Background Image of Panel at particular position is it possible.. this is another issue ..how can i do this .. Via the FontDialog I have retrieved a font. After saving the font (in an XML document) and retrieving it again, I have a string in the following "format"; [Font: Name=Arial, Size=9, Units=3, GdiCharSet=0, GdiVerticalFont=False] How can I convert this string (back) to a font object? So that I can assign this to (for example) to: label1.Font = .... Thanks! | | dilipkumarmdk Tuesday, May 05, 2009 10:27 AM | I'd like to suggest you start a new thread for your new problems. By starting a new thread, many more community members who have similar experience will give you expert advice and help you sovle the problem quickly after they see it. Best regards, Bruce Zhou Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Tuesday, May 05, 2009 10:33 AM | Hi Bruce.. Please solve my problem.. because you understood my project.. What my problem is ..In my form having one control is there..suppose i will take another control and Drop on panel check before that position having control is there or not.. and when i moving any control check whether that position having any control or not..if any control is there stop the moving.. Please solve my quesation.. Thanks | | dilipkumarmdk Tuesday, May 12, 2009 6:27 AM |
|