H
HugovanN
Guest
Hello all. I have this problem for a long time in VS2019. The software I wrote started off in 1978 before IBM compatibles were on the market and have been upgrading it through GW basic, Quick basic, Turbo basic, Visual basic all versions to VB6 pro, VS2008, VS2013 and now VS2019.
The conversion is now 98% complete with a few hiccup's.
I have a form with a picture box that is used in a Cad program. Before I used Autoredraw function to draw on background and used foreground as overlay. Now in VS2019 I use bitmaps on fore and background so to make it easy for panning and zoom functions since Autoredraw also do not exist anymore.
The code I used in VB6 was:
frmCad.picCad.FillStyle = vbFSTransparent
ExtFloodFill frmCad.picCad.hDC, Lax!, Lay!, frmCad.picCad.Point(RX1!, RY1!), 1
Where picCad is my picture box and that was all that was needed.
I have played around with sample code for hatchbrush but the floodfill IE. filling a color with a hatch was not available.
Using path also is not viable. So using GDI32 was my only option except that the interrupt used in GDI needs to be from graphics derived from an object like 'picture box' where I now have graphics derived from a bitmap that is not an object.
Sorry for my lack of understanding of VB2019. Please tell me what is wrong with code that follows. The hatch-brush do not work correct and if I DIM graphics from picture box it works except with 'pic.refresh' then bitmap wipes hatch out. So I need to use Pic instead of Grafika for the Hdc.
Public oMatrix As New Matrix()
Public bitPic As Bitmap = New Bitmap(1680, 1000)
Public bitFPic As Bitmap = New Bitmap(1680, 1000)
Public Pic As Graphics = Graphics.FromImage(bitPic)
Public PicFore As Graphics = Graphics.FromImage(bitFPic)
Public myPen As Pen = New Pen(Color.Yellow, 1)
From form load:
PicCad.BackgroundImage = bitPic
PicCad.Image = bitFPic
From drawing part:
Dim fcolor As Int32 = Color.White.ToArgb
Dim hBrush As IntPtr = NativeMethods.CreateHatchBrush(Punt1(1, J).Etype, fcolor)
GdiErr = NativeMethods.SetBkMode(hBrush, 1) ' 1 = transparent 2 = OPAQUE
Label2.Text = Str(GdiErr)
Dim Grafika As Graphics = PicCad.CreateGraphics()
'this works but on PicCad and need to use graphics Pic
Dim Hdc As IntPtr = Grafika.GetHdc() 'Pic.GetHdc()
Dim Last As IntPtr = NativeMethods.SelectObject(Hdc, hBrush)
GdiErr = NativeMethods.ExtFloodFill(Hdc, Lax, Lay, ccolor, 1)
'FLOODFILL to BORDER = 0 FLOODFILL to SURFACE on color = 1;
Label3.Text = Str(GdiErr)
NativeMethods.SelectObject(Hdc, Last)
GdiErr = NativeMethods.DeleteObject(hBrush)
Label4.Text = Str(GdiErr)
Grafika.ReleaseHdc()
'Pic.ReleaseHdc()
Any advice will be appreciated.
Continue reading...
The conversion is now 98% complete with a few hiccup's.
I have a form with a picture box that is used in a Cad program. Before I used Autoredraw function to draw on background and used foreground as overlay. Now in VS2019 I use bitmaps on fore and background so to make it easy for panning and zoom functions since Autoredraw also do not exist anymore.
The code I used in VB6 was:
frmCad.picCad.FillStyle = vbFSTransparent
ExtFloodFill frmCad.picCad.hDC, Lax!, Lay!, frmCad.picCad.Point(RX1!, RY1!), 1
Where picCad is my picture box and that was all that was needed.
I have played around with sample code for hatchbrush but the floodfill IE. filling a color with a hatch was not available.
Using path also is not viable. So using GDI32 was my only option except that the interrupt used in GDI needs to be from graphics derived from an object like 'picture box' where I now have graphics derived from a bitmap that is not an object.
Sorry for my lack of understanding of VB2019. Please tell me what is wrong with code that follows. The hatch-brush do not work correct and if I DIM graphics from picture box it works except with 'pic.refresh' then bitmap wipes hatch out. So I need to use Pic instead of Grafika for the Hdc.
Public oMatrix As New Matrix()
Public bitPic As Bitmap = New Bitmap(1680, 1000)
Public bitFPic As Bitmap = New Bitmap(1680, 1000)
Public Pic As Graphics = Graphics.FromImage(bitPic)
Public PicFore As Graphics = Graphics.FromImage(bitFPic)
Public myPen As Pen = New Pen(Color.Yellow, 1)
From form load:
PicCad.BackgroundImage = bitPic
PicCad.Image = bitFPic
From drawing part:
Dim fcolor As Int32 = Color.White.ToArgb
Dim hBrush As IntPtr = NativeMethods.CreateHatchBrush(Punt1(1, J).Etype, fcolor)
GdiErr = NativeMethods.SetBkMode(hBrush, 1) ' 1 = transparent 2 = OPAQUE
Label2.Text = Str(GdiErr)
Dim Grafika As Graphics = PicCad.CreateGraphics()
'this works but on PicCad and need to use graphics Pic
Dim Hdc As IntPtr = Grafika.GetHdc() 'Pic.GetHdc()
Dim Last As IntPtr = NativeMethods.SelectObject(Hdc, hBrush)
GdiErr = NativeMethods.ExtFloodFill(Hdc, Lax, Lay, ccolor, 1)
'FLOODFILL to BORDER = 0 FLOODFILL to SURFACE on color = 1;
Label3.Text = Str(GdiErr)
NativeMethods.SelectObject(Hdc, Last)
GdiErr = NativeMethods.DeleteObject(hBrush)
Label4.Text = Str(GdiErr)
Grafika.ReleaseHdc()
'Pic.ReleaseHdc()
Any advice will be appreciated.
Continue reading...