The following code just shows a small portion of the overall Graphics on my
Sweep form. I set the Panel to
a medium Grey color so it stands out on a Windows Grey screen. The first
thing that should happen is it should be painted Black. It just stays medium
Grey !!!!
Any help would be appreciated.
GalenS
The Form_Load event just starts a short Timer1.
The Timer1 disables itself and does the following, among other stuff, before
things happen.
Form declares
Public PicDraw As Graphics
Public PictMap As Bitmap
PictDraw is a Panel and glngColors(1) is Black
With PictDraw
.Top = 0
.Left = 0
.Height = 450
.Width = gScreen.HorPixels '1024
End With
PictDraw.Visible = True
PicDraw = PictDraw.CreateGraphics
PictMap = New Bitmap(PictDraw.Width, PictDraw.Height, PicDraw)
PicDraw.Dispose()
PicDraw = Graphics.FromImage(PictMap)
Dim Sbrush As New
System.Drawing.SolidBrush(Color.FromArgb(glngColor s(1)))
PicDraw.FillRectangle(Sbrush, 0, 0, PictDraw.Width, PictDraw.Height)
PictDraw.Invalidate()
bitmapflg = True
This is the Paint event, naturally.
Private Sub PictDraw_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictDraw.Paint
If bitmapflg Then
e.Graphics.DrawImage(PictMap, e.ClipRectangle,
e.ClipRectangle, _
GraphicsUnit.Pixel)
End If
End Sub
This is a sub in a module. It stops at the AGAIN label so I can see what the
PictDraw panel looks like on screen. Then it draws tick marks at top and
bottom of panel.
It stops at the AGAIN1 label. Of course it doesn't work.
Public Sub SetIndex()
Dim X2, X1, Y1, Y2 As Short
Dim Incr As Single, p As New Pen(Color.Black)
Dim Index As Short, c As Color
Dim BackCol As Integer
Dim ForeCol As Integer
Dim Currfrm As Object
Dim CurrHgt As Integer
BackCol = glngColors(1)
ForeCol = glngColors(0)
Currfrm = frmSweep.PicDraw
CurrHgt = frmSweep.PictMap.Height
Incr = CSng(gScreen.HorPixels) / 16
gbut1flg = False
AGAIN:
System.Windows.Forms.Application.DoEvents()
If Not gbut1flg Then GoTo AGAIN 'Button1
Currfrm.clear(Color.FromArgb(BackCol))
p.Color = Color.FromArgb(ForeCol)
X1 = 0
Y1 = 0
X2 = X1
Y2 = Y1 + 10
For Index = 1 To 17 Step 1
Currfrm.DrawLine(p, X1, Y1, X2, Y2)
X1 = CSng(Index) * Incr
If Index = 16 Then X1 = gScreen.HorPixels - 1
X2 = X1
Next Index
X1 = 0
Y2 = CurrHgt
X2 = X1
Y1 = Y2 - 10
For Index = 1 To 17 Step 1
Currfrm.DrawLine(p, X1, Y1, X2, Y2)
X1 = CSng(Index) * Incr
If Index = 16 Then X1 = gScreen.HorPixels - 1
X2 = X1
Next Index
p.Dispose()
frmSweep.PictDraw.Invalidate()
gbut2flg = False
AGAIN1:
System.Windows.Forms.Application.DoEvents()
If Not gbut2flg Then GoTo AGAIN1 'Button2
End Sub 17 1416
Galen Somerville wrote: The following code just shows a small portion of the overall Graphics on my Sweep form. I set the Panel to a medium Grey color so it stands out on a Windows Grey screen. The first thing that should happen is it should be painted Black. It just stays medium Grey !!!!
Where have you placed this code?
"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com... Galen Somerville wrote: The following code just shows a small portion of the overall Graphics on my Sweep form. I set the Panel to a medium Grey color so it stands out on a Windows Grey screen. The first thing that should happen is it should be painted Black. It just stays medium Grey !!!!
Where have you placed this code?
As shown by this, the first section of code is in the Form
The Form_Load event just starts a short Timer1.
The Timer1 disables itself and does the following, among other stuff, before
things happen.
Then the rest is in a module as shown by this
This is a sub in a module. It stops at the AGAIN label so I can see what the
PictDraw panel looks like on screen. Then it draws tick marks at top and
bottom of panel.
GalenS
"Galen Somerville" <ga***@community.nospam> schrieb The following code just shows a small portion of the overall Graphics on my Sweep form. I set the Panel to a medium Grey color so it stands out on a Windows Grey screen. The first thing that should happen is it should be painted Black. It just stays medium Grey !!!!
Any help would be appreciated.
GalenS
The Form_Load event just starts a short Timer1.
The Timer1 disables itself and does the following, among other stuff, before things happen.
I tried to understand but I do not see where the code in the Module is
called. I can make the code in the Form run without the Module, so I don't
know why I need it. The panel gets black when painted. In addition, many
declarations are missing, in the Module. I can only guess that the Module is
accessing a different instance of the Form, not the visible one.
Armin
"Armin Zingler" <az*******@freenet.de> wrote in message
news:eM*************@TK2MSFTNGP10.phx.gbl... "Galen Somerville" <ga***@community.nospam> schrieb The following code just shows a small portion of the overall Graphics on my Sweep form. I set the Panel to a medium Grey color so it stands out on a Windows Grey screen. The first thing that should happen is it should be painted Black. It just stays medium Grey !!!!
Any help would be appreciated.
GalenS
The Form_Load event just starts a short Timer1.
The Timer1 disables itself and does the following, among other stuff, before things happen.
I tried to understand but I do not see where the code in the Module is called. I can make the code in the Form run without the Module, so I don't know why I need it. The panel gets black when painted. In addition, many declarations are missing, in the Module. I can only guess that the Module is accessing a different instance of the Form, not the visible one.
Armin
The module was shown just to illustrate that additional drawing would be
done. The module was not called in the code I supplied. There is probably
two dozen subs that draw to the Panel.
I made a test form and copied all of the code shown. I added a module and
copied that code also.
I added a call to the module sub by clicking a button. Like you said, it
worked fine. I clicked the button and had errors. Fixed the code in the
module and now the whole thing runs fine.
In the test form Load event I added a Timer. So all of the code in the test
form is EXACTLY like the real code.
So why doesn't it work in my real app????
I did a search for PictDraw in the real app and in the test form. Everything
the same !!
Now what?
GalenS
"Armin Zingler" <az*******@freenet.de> wrote in message
news:eM*************@TK2MSFTNGP10.phx.gbl... "Galen Somerville" <ga***@community.nospam> schrieb The following code just shows a small portion of the overall Graphics on my Sweep form. I set the Panel to a medium Grey color so it stands out on a Windows Grey screen. The first thing that should happen is it should be painted Black. It just stays medium Grey !!!!
Any help would be appreciated.
GalenS
The Form_Load event just starts a short Timer1.
The Timer1 disables itself and does the following, among other stuff, before things happen.
I tried to understand but I do not see where the code in the Module is called. I can make the code in the Form run without the Module, so I don't know why I need it. The panel gets black when painted. In addition, many declarations are missing, in the Module. I can only guess that the Module is accessing a different instance of the Form, not the visible one.
Armin
Armin
I added to the Paint event as follows:
Private Sub PictDraw_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictDraw.Paint
If bitmapflg Then
e.Graphics.DrawImage(PictMap, e.ClipRectangle, e.ClipRectangle,
GraphicsUnit.Pixel)
If mapflg Then
PictMap.Save("testbitmap.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)
mapflg = False
Button1.BackColor = Color.Black
End If
End If
End Sub
No matter where in the application I placed "mapflg = True", the
"testbitmap.jpg" file always shows the proper Black background.
This has to mean that the PictDraw Paint event isn't doing it's job as the
Panel remains Grey
Any ideas on where to look??
GalenS
..
On Fri, 17 Mar 2006 14:11:28 -0800, "Galen Somerville"
<ga***@community.nospam> wrote: The following code just shows a small portion of the overall Graphics on my Sweep form. I set the Panel to a medium Grey color so it stands out on a Windows Grey screen. The first thing that should happen is it should be painted Black. It just stays medium Grey !!!!
Any help would be appreciated.
GalenS
The Form_Load event just starts a short Timer1.
The Timer1 disables itself and does the following, among other stuff, before things happen.
Form declares Public PicDraw As Graphics Public PictMap As Bitmap
PictDraw is a Panel and glngColors(1) is Black
With PictDraw .Top = 0 .Left = 0 .Height = 450 .Width = gScreen.HorPixels '1024 End With PictDraw.Visible = True PicDraw = PictDraw.CreateGraphics PictMap = New Bitmap(PictDraw.Width, PictDraw.Height, PicDraw) PicDraw.Dispose() PicDraw = Graphics.FromImage(PictMap) Dim Sbrush As New System.Drawing.SolidBrush(Color.FromArgb(glngColo rs(1))) PicDraw.FillRectangle(Sbrush, 0, 0, PictDraw.Width, PictDraw.Height) PictDraw.Invalidate() bitmapflg = True
The line,System.Drawing.SolidBrush(Color.FromArgb(glng Colors(1)))
makes no sense.
What happens if you change it to:
Dim Sbrush As New System.Drawing.SolidBrush(Color.Black)
or
Dim MyColor As Color = Color.FromArgb(0, 0, 0)
Dim Sbrush As New System.Drawing.SolidBrush(MyColor)
Gene
"gene kelley" <ok**@by.me> wrote in message
news:ua********************************@4ax.com... On Fri, 17 Mar 2006 14:11:28 -0800, "Galen Somerville" <ga***@community.nospam> wrote:
The following code just shows a small portion of the overall Graphics on my Sweep form. I set the Panel to a medium Grey color so it stands out on a Windows Grey screen. The first thing that should happen is it should be painted Black. It just stays medium Grey !!!!
Any help would be appreciated.
GalenS
The Form_Load event just starts a short Timer1.
The Timer1 disables itself and does the following, among other stuff, before things happen.
Form declares Public PicDraw As Graphics Public PictMap As Bitmap
PictDraw is a Panel and glngColors(1) is Black
With PictDraw .Top = 0 .Left = 0 .Height = 450 .Width = gScreen.HorPixels '1024 End With PictDraw.Visible = True PicDraw = PictDraw.CreateGraphics PictMap = New Bitmap(PictDraw.Width, PictDraw.Height, PicDraw) PicDraw.Dispose() PicDraw = Graphics.FromImage(PictMap) Dim Sbrush As New System.Drawing.SolidBrush(Color.FromArgb(glngCol ors(1))) PicDraw.FillRectangle(Sbrush, 0, 0, PictDraw.Width, PictDraw.Height) PictDraw.Invalidate() bitmapflg = True The line,System.Drawing.SolidBrush(Color.FromArgb(glng Colors(1))) makes no sense. What happens if you change it to: Dim Sbrush As New System.Drawing.SolidBrush(Color.Black)
or
Dim MyColor As Color = Color.FromArgb(0, 0, 0) Dim Sbrush As New System.Drawing.SolidBrush(MyColor)
Gene
This is a VB6 conversion and the glngColors() was RGB. It is an array of
colors chosen by the user. This info and other user choices are saved to and
read from a file.
Since starting this thread I have laboriously gone through the program and
now all color references use the net color scheme.
Per my last posting, the bitmap PictMap does change to Black but just
doesn't get painted to the screen.
I think Armin mentioned that maybe it's posting to the wrong form. The form
in question is named frmSweep but it is called from frmMain as follows:
Dim hFrm As frmSweep
hFrm = New frmSweep
frmSweep.Show()
Me.Hide()
frmMain is always there regardless of what form is active.
GalenS
Hello Galen,
Is this the exact code you're using?
Dim hFrm As frmSweep
hFrm = New frmSweep 'Create new instance
frmSweep.Show() 'Show default instance
'Add this line:
msgbox(frmSweep Is hFrm) 'You will see that you have two distinct instances of the form.
Me.Hide()
Regards.
"José Manuel Agüero" <chema012 en hotmail.com> wrote in message
news:un**************@TK2MSFTNGP11.phx.gbl...
Hello Galen,
Is this the exact code you're using?
Dim hFrm As frmSweep
hFrm = New frmSweep 'Create new instance
frmSweep.Show() 'Show default instance
'Add this line:
msgbox(frmSweep Is hFrm) 'You will see that you have two distinct
instances of the form.
Me.Hide()
Regards.
Yep, that's the exact code. In VB6 you could F1 and generally get the help
needed.
In VB2005, and I assume any net product, if you pick an item and F1, you get
literally hundreds of answes.
I've read so much on opening an SDI type of form that I have a headache.
What code should I use?
GalenS
Respect to the help, try clicking the word you want help about, but do not select it (in other words, put the caret in the word). Then press F1.
Respect the form, if you will have only one instance of it, use the default instance. To do so, refer always to it with its class name: frmSweep.
Do not create instances: search your code for "New frmSweep" and delete the variable to which it's assigned.
hFrm = New frmSweep 'Delete this line and the declaration of hFrm (dim hfrm as frmsweep). Change any subsequent access to hFrm, to frmSweep.
If you use more than one instance of frmSweep, in my opinion you shouldn't use the default instance: only instances created and controled by your code.
Regards.
"Galen Somerville" <ga***@community.nospam> escribió en el mensaje news:et**************@TK2MSFTNGP09.phx.gbl...
|
| "José Manuel Agüero" <chema012 en hotmail.com> wrote in message
| news:un**************@TK2MSFTNGP11.phx.gbl...
| Hello Galen,
|
| Is this the exact code you're using?
|
| Dim hFrm As frmSweep
| hFrm = New frmSweep 'Create new instance
| frmSweep.Show() 'Show default instance
| 'Add this line:
| msgbox(frmSweep Is hFrm) 'You will see that you have two distinct
| instances of the form.
| Me.Hide()
|
| Regards.
|
| Yep, that's the exact code. In VB6 you could F1 and generally get the help
| needed.
|
| In VB2005, and I assume any net product, if you pick an item and F1, you get
| literally hundreds of answes.
|
| I've read so much on opening an SDI type of form that I have a headache.
|
| What code should I use?
|
| GalenS
Okay, I did that in several places on my frmMain so they now read
frmSweep.Show
Me.Hide
or
frmColor.Show
Me.Hide
However the PickDraw panel on frmSweep still doesn't change to Black. The
following code must run because when I view "testbitmap.jpg" in a graphics
program, it is Black. Also the temporary Button1 turns black
Private Sub PictDraw_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictDraw.Paint
If bitmapflg Then
e.Graphics.DrawImage(PictMap, e.ClipRectangle, e.ClipRectangle,
GraphicsUnit.Pixel)
If mapflg Then
PictMap.Save("testbitmap.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)
mapflg = False
Button1.BackColor = Color.Black
End If
End If
End Sub
GalenS
"José Manuel Agüero" <chema012 en hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP11.phx.gbl...
Respect to the help, try clicking the word you want help about, but do not
select it (in other words, put the caret in the word). Then press F1.
Respect the form, if you will have only one instance of it, use the default
instance. To do so, refer always to it with its class name: frmSweep.
Do not create instances: search your code for "New frmSweep" and delete the
variable to which it's assigned.
hFrm = New frmSweep 'Delete this line and the declaration of hFrm (dim
hfrm as frmsweep). Change any subsequent access to hFrm, to frmSweep.
If you use more than one instance of frmSweep, in my opinion you shouldn't
use the default instance: only instances created and controled by your code.
Regards.
"Galen Somerville" <ga***@community.nospam> escribió en el mensaje
news:et**************@TK2MSFTNGP09.phx.gbl...
|
| "José Manuel Agüero" <chema012 en hotmail.com> wrote in message
| news:un**************@TK2MSFTNGP11.phx.gbl...
| Hello Galen,
|
| Is this the exact code you're using?
|
| Dim hFrm As frmSweep
| hFrm = New frmSweep 'Create new instance
| frmSweep.Show() 'Show default instance
| 'Add this line:
| msgbox(frmSweep Is hFrm) 'You will see that you have two distinct
| instances of the form.
| Me.Hide()
|
| Regards.
|
| Yep, that's the exact code. In VB6 you could F1 and generally get the help
| needed.
|
| In VB2005, and I assume any net product, if you pick an item and F1, you
get
| literally hundreds of answes.
|
| I've read so much on opening an SDI type of form that I have a headache.
|
| What code should I use?
|
| GalenS
On Sun, 19 Mar 2006 14:52:51 -0800, "Galen Somerville"
<ga***@community.nospam> wrote: Okay, I did that in several places on my frmMain so they now read frmSweep.Show Me.Hide
or frmColor.Show Me.Hide
However the PickDraw panel on frmSweep still doesn't change to Black. The following code must run because when I view "testbitmap.jpg" in a graphics program, it is Black. Also the temporary Button1 turns black
Private Sub PictDraw_Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictDraw.Paint If bitmapflg Then e.Graphics.DrawImage(PictMap, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel) If mapflg Then PictMap.Save("testbitmap.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) mapflg = False Button1.BackColor = Color.Black End If End If End Sub
GalenS
What version are you using?
PictMap.Save(.............. is not valid in VB2005.
PictMap.Save.Image(............. works.
I'd offer some help, but don't have a clue as to what you are trying
to accomplish. Based on what code you show, I (and others) have no
problem showing a gray panel as black when the program is run. What
is the purpose of drawing the color to the panel versus setting the
panel's backcolor to black?
Gene
"gene kelley" <ok**@by.me> schrieb I'd offer some help, but don't have a clue as to what you are trying to accomplish. Based on what code you show, I (and others) have no problem showing a gray panel as black when the program is run. What is the purpose of drawing the color to the panel versus setting the panel's backcolor to black?
Galen, I agree with Gene. I followed the discussion because I was trying to
help but I can not follow what's your intention. Can't you narrow the
problem down to fewer lines of code? If possible, drop me a mail (replace
"nospam" by "no_spam" in my address) and send me the zipped project.
Armin
I don't know what can be happening.
Try to review the properties of the panel. Specifically, set a background color different from the form's background color.
Try to draw any other thing in the panel:
Private Sub PictDraw_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictDraw.Paint
If bitmapflg Then
e.Graphics.DrawImage(PictMap, e.ClipRectangle, e.ClipRectangle,
GraphicsUnit.Pixel)
If mapflg Then
PictMap.Save("testbitmap.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)
mapflg = False
Button1.BackColor = Color.Black
End If
End If
e.Graphics.DrawRectangle(Pens.Red, 20, 20, 200, 200)
End Sub
"Galen Somerville" <ga***@community.nospam> escribió en el mensaje news:eF*************@TK2MSFTNGP09.phx.gbl...
| Okay, I did that in several places on my frmMain so they now read
| frmSweep.Show
| Me.Hide
|
| or
| frmColor.Show
| Me.Hide
|
| However the PickDraw panel on frmSweep still doesn't change to Black. The
| following code must run because when I view "testbitmap.jpg" in a graphics
| program, it is Black. Also the temporary Button1 turns black
|
| Private Sub PictDraw_Paint(ByVal sender As Object, _
| ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictDraw.Paint
| If bitmapflg Then
| e.Graphics.DrawImage(PictMap, e.ClipRectangle, e.ClipRectangle,
| GraphicsUnit.Pixel)
| If mapflg Then
| PictMap.Save("testbitmap.jpg",
| System.Drawing.Imaging.ImageFormat.Jpeg)
| mapflg = False
| Button1.BackColor = Color.Black
| End If
| End If
| End Sub
|
| GalenS
|
| "José Manuel Agüero" <chema012 en hotmail.com> wrote in message
| news:uU**************@TK2MSFTNGP11.phx.gbl...
| Respect to the help, try clicking the word you want help about, but do not
| select it (in other words, put the caret in the word). Then press F1.
|
| Respect the form, if you will have only one instance of it, use the default
| instance. To do so, refer always to it with its class name: frmSweep.
| Do not create instances: search your code for "New frmSweep" and delete the
| variable to which it's assigned.
| hFrm = New frmSweep 'Delete this line and the declaration of hFrm (dim
| hfrm as frmsweep). Change any subsequent access to hFrm, to frmSweep.
|
| If you use more than one instance of frmSweep, in my opinion you shouldn't
| use the default instance: only instances created and controled by your code.
|
| Regards.
|
|
| "Galen Somerville" <ga***@community.nospam> escribió en el mensaje
| news:et**************@TK2MSFTNGP09.phx.gbl...
||
|| "José Manuel Agüero" <chema012 en hotmail.com> wrote in message
|| news:un**************@TK2MSFTNGP11.phx.gbl...
|| Hello Galen,
||
|| Is this the exact code you're using?
||
|| Dim hFrm As frmSweep
|| hFrm = New frmSweep 'Create new instance
|| frmSweep.Show() 'Show default instance
|| 'Add this line:
|| msgbox(frmSweep Is hFrm) 'You will see that you have two distinct
|| instances of the form.
|| Me.Hide()
||
|| Regards.
||
|| Yep, that's the exact code. In VB6 you could F1 and generally get the help
|| needed.
||
|| In VB2005, and I assume any net product, if you pick an item and F1, you
| get
|| literally hundreds of answes.
||
|| I've read so much on opening an SDI type of form that I have a headache.
||
|| What code should I use?
||
|| GalenS
|
|
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... "gene kelley" <ok**@by.me> schrieb I'd offer some help, but don't have a clue as to what you are trying to accomplish. Based on what code you show, I (and others) have no problem showing a gray panel as black when the program is run. What is the purpose of drawing the color to the panel versus setting the panel's backcolor to black? Galen, I agree with Gene. I followed the discussion because I was trying to help but I can not follow what's your intention. Can't you narrow the problem down to fewer lines of code? If possible, drop me a mail (replace "nospam" by "no_spam" in my address) and send me the zipped project.
Armin
Gene, Jose, Armin
First let me say I found the problem. When the app is run the first time and
there is no user file, the program sets up defaults for the 12 user
selectable colors and other items. The user can change them at any time on
any run.
When the program exits, especially the first time, a user file is created.
Thereafter the app reads this user file every time it starts up.
The colors were saved correctly as argb however when reading the file at
program start the colors were read in as rgb (no a) and that was the
problem.
However I have a new problem. A USB device samples a Heart sound and ECG
about every 3.9 milliseconds. Four samples are collected and sent to the
Host about every 12 ms. These four samples are drawn as lines connecting the
appropriate pixels, as we walk across the screen.
Naturally (?) I have to invalidate the Panel after each set of four pixels
are drawn. This makes an oscilloscope type of delay. The display works fine
in that you can watch it walk across the screen (and hear the sound
properly).
But there are horizontal bands of Grey fluttering up and down the display.
It appears that somehow I will have to synch the invalidations to the screen
updates.
Any ideas ??
GalenS
The only thing I can think of is that the panel is not double buffered
by default. I had a (much simpler) program where I was redrawing a
panel and it had the same flickering, so I created a new panel that
inherited from the Panel control and turned on double buffering and
that helped.
If double buffering does not help, then I have no more ideas, sorry.
"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com... The only thing I can think of is that the panel is not double buffered by default. I had a (much simpler) program where I was redrawing a panel and it had the same flickering, so I created a new panel that inherited from the Panel control and turned on double buffering and that helped.
If double buffering does not help, then I have no more ideas, sorry.
Thanks, I'll look into that
GalenS This thread has been closed and replies have been disabled. Please start a new discussion. |