What does the e mean?

realolman
04-19-2006, 06:57 PM
Protected Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
End Sub

This seems like something I should know, but I can't seem to find it. I have looked in 4 books and the MSDN.

What does the e As System.EventArgs mean?

I have seen similar things in graphics (g?)

thanks

MikeJ
04-19-2006, 07:02 PM
e is just the notation that .Net uses as a way to inherit Event Arguments. I've never tried it, but you could just as easily change it to some other variable, it just is the variable name (for reference purposes) by which event args are passed to the method.

inighthawki
04-19-2006, 07:54 PM
i don't think it really has any real meaning, but as stated, its the common name used for that specific variable. For example under keydown, the event args could be e.keycode, e.keydata, e.modifier(?) and under paint it could be e.graphics (substitues <object>.creategraphics) etc. Even if it does has a true meaning behind why it's an e, i don't think it really matters ;) And as for changing it, it should work just fine since its declared as e, and u should be able to label the var anything...

shaul_ahuva
04-19-2006, 08:42 PM
The EventArgs class (and inherited classes) seem to be a variation of the Command pattern (http://en.wikipedia.org/wiki/Command_pattern). You don't necessarily need to follow this pattern when creating your own events but there are advantages.

When dealing with BCL objects such as Form or Button, some events may used a specialized EventArgs class (such as CancelEventArgs in the case of a Form.Closing event) or they may use EventArgs.Empty (in the case of a Button.Click event where there's no specialized data for the event).

I think MikeJ answered the naming convention aspect very well :)

realolman
04-20-2006, 04:16 PM
or they may use EventArgs.Empty (in the case of a Button.Click event where there's no specialized data for the event).




so in the case of the button click event it means nothing?



Most, if not all of what follows is from the tutor's corner by MikeJ re: GDI+.


I understood the drawing stuff in the OnPaint event.

I really don't know where I got the other stuff... I think it is supposed to print a part of the form. That's what I would like to do, draw smoe stuff on a form or picture box and then print it. Music actually.

It operates the printer, fires thru a piece of paper but doesn't print anything
Although there is about two and a half tons of stuff I don't understand here, I had hoped to at least get the

e.Graphics.FromImage(memoryImage)

a little better

Public Class Form1
Inherits System.Windows.Forms.Form

Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _
hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _
Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _
hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As System.Int32) As Long
Dim memoryImage As Bitmap

#Region " Windows Form Designer generated code "

Private Sub CaptureScreen()
Dim mygraphics As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
Dim dc1 As IntPtr = mygraphics.GetHdc
Dim dc2 As IntPtr = memoryGraphics.GetHdc
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, _
Me.ClientRectangle.Height, dc1, 0, 0, 13369376)
mygraphics.ReleaseHdc(dc1)
memoryGraphics.ReleaseHdc(dc2)
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument1.PrintPage
e.Graphics.FromImage(memoryImage)


End Sub
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles PrintButton.Click
CaptureScreen()
PrintDocument1.Print()


'PrintPreviewDialog1.Document = PrintDocument1
'PrintPreviewDialog1.Show()
End Sub



Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'This is the declare of the Graphics object
Dim g As Graphics = e.Graphics
'Declare the pen
Dim pPen As Pen = New Pen(Color.Maroon, 4)

'Let's draw us a line
g.DrawLine(pPen, 10, 10, 1100, 1100)
'Declare the Rectangle
Dim rRect As Rectangle = New Rectangle(150, 150, 100, 100)

'Let's draw us a rectangle!
g.DrawRectangle(pPen, rRect)
'Fill it!
g.FillRectangle(New SolidBrush(Color.Blue), rRect)
'Declare the font
Dim fFont As Font = New Font("Verdana", 10, FontStyle.Bold)
'Draw some text
g.DrawString("Hello World! I'm GDI!", fFont, New SolidBrush(Color.Orange), 30, 100)

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class


I understand the code in the OnPaint event, but not much else.

What is happening here?

Thanks

shaul_ahuva
04-20-2006, 04:29 PM
so in the case of the button click event it means nothing?
It means there's no data specific to the event. The only data you really need is where the event is coming from (which is provided by the sender argument).

What is happening here?
You're not drawing anything with the graphics object in the PrintPage handler. I think you want e.Graphics.DrawImage :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum