The region class is defined in .Net so in vb6 you have to make an ActiveX and change its region to the corresponding shape using API functions.or you can add a control like picturebox to your form and using its hwnd and APIs change its shape.
so when you add this ActiveX to your project you will be able to use its events and a picturebox has its own mouse events.
If you will store and render the polygon with a GraphicsPath object, you can do hit testing with the properties: .IsVisible and .IsOutlineVisible
I have been using the GraphicsPath object in a vector graphics program I'm writing. You have do hit testing all the time in these types of programs.
This is pretty lengthy but I think it will get you going. I had to convert the original code from C# into VB.NET code.
Create a new class and call it: ShapeManager. Once the class file opens, replace all code with this code below: (Note: Copy down until you see: "End Code"
'Start Code below
Public Class ShapeManager
'//All shapes will be exposed through this collection
Public Shapes As System.Collections.ArrayList
Public Sub PaintShapes(ByVal g As Graphics)
'note: the clipping area should already be set
'in the graphics object through this.Invalidate()
'We will now loop through all the shapes and paint
'only those that are part of the clipping rectangle.
'Processing is faster if we use a Int in our For loop
'instead of the ArrayList.Count property
Dim intCount As Short = Convert.ToInt16(Shapes.Count - 1)
For intNum As Short = 0 To intCount
'Don't send shape to graphics object if it's bounds
'do not fall inside the clipbounds. This helps when
'you have thousands of shapes and you are only wanting to
'update a small portion of the screen. For more info, do a
'search on Graphics.Clipping
Dim curShape As MyShape = CType(Shapes(intNum), MyShape)
If curShape.IsInsideClipBounds(g.ClipBounds) Then
'ensure that our Path object has been initialized
If Not curShape.Path Is Nothing Then
'Sample paint code
g.FillPath(New SolidBrush(curShape.FillColor), curShape.Path)
g.DrawPath(New Pen(curShape.LineColor), curShape.Path)
Public Class MyShape
Public Path As GraphicsPath
Public LineColor As Color
Public FillColor As Color
Public Sub New()
'Allows us to create a new shape without having to pass
'any initial properties
Public Sub New(ByVal gp As GraphicsPath, ByVal lineColor As Color, ByVal fillColor As Color)
'Initialize the shape
Path = gp
lineColor = lineColor
fillColor = fillColor
'*** Here's the function that will help you ***
Public Function ContainsMousePoint(ByVal pnt As Point) As Boolean
'A more common name for this function is HitTest but I think
'you'll connect with this name better. The pnt passed to us
'should be the location of the mouse.
If Not Path Is Nothing Then
Public Function IsInsideClipBounds(ByVal clipBounds As RectangleF) As Boolean
The way to wire this up to your form is to trap your form's MouseDown event
and write some code like the example below:
Dim shapeManager As New ShapeManager()
Private Sub frmMain_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Dim intCount As Short = Convert.ToInt16(shapeManager.Shapes.Count - 1)
For intNum As Short = 0 To intCount
Dim curShape As MyShape = CType(shapeManager.Shapes(intNum), MyShape)
If curShape.ContainsMousePoint(e.Location) Then
MessageBox.Show("The mouse hit me!")
Dim getipaddress As String
Dim xAddr As System.Net.IPAddress
Dim vAddr As String
xAddr = New System.Net.IPAddress(.AddressList(0).Address)
vAddr = xAddr.ToString
getipaddress = vAddr
that's the syntax for .net but i'd imagine it would be somewhat similar in 6
I am using VB 2005 & in my form all control are bound. I have Client Name field. I want to display all names in a combo, let the user select & bound the selected text to the client name field of DB. How do I achieve this?
Currently, I am using a trick for it - a combo box which has all names, when user select put the selected name in an invisilbe text field which is bound to the field. Client names will be taken from other table. In other case, combo will be filled by values but the scenario is the same. I Know & belive that this is a wrong way, professionally speaking. I would like to know is their a better and proper way for the operation.
Prog. is using the Binding to DB method, so operations are not done by manual code.
It is a data entry form & all fields are dragged from dataset to the form & hence they are bound automatically. The displaying respective fields in respective text box is managed by BindingSource only. I am not writtting any code for Add, SAve, Update, dEl etc.
I have data set with 3 tables. In table 1, i have id & name. In table 2 i have name, source & other fields.
* I want to display all names from table 1 and the selected name should be bound with name field of table 2
* For source field, I want user to enter items from 4 only. So, i thought of combo box. The point is how do I bind the combobox with that source field of table.
So, how do I make the bound sure of combobox with the field of table. How such a task be achieved.