|
wouldn't the Shown event be good enough here? I expect all outstanding Windows messages caused inside the Load handler will have been processed by then and the DGV will have been fully populated.
|
|
|
|
|
Probably I forgot all about the Shown event never use to exist before .Net 2, and probably I just got stuck in my ways!
|
|
|
|
|
Hello all!
I am trying to draw two ellipses, both centered on the mouse cursor during a click event.
Currently, I have to offset the X and Y coordinates to do this. This is fine for my first circle, which is of a static size. However, my second circle is variable in size and will always be larger than the first circle.
I am having trouble with this, as I am unable to determine what sort of equation I could use to account for all of the different sizes. Is there a way to have it draw the circle with the cursor position as the center of the circle. Is this at all possible with VB.NET, or am I going to need to start learning C++?
If any code is needed, please let me know and I will provide it.
Thanks in advance!
|
|
|
|
|
ChrisDScott93 wrote: I am unable to determine what sort of equation I could use to account for all of the different sizes.
You have not explained what you are using to determine the size in the first place. Is it something to do with the current mouse position or some sort of offset based on who knows what?
ChrisDScott93 wrote: Is there a way to have it draw the circle with the cursor position as the center of the circle.
I'm sure that is the standard way of drawing a circle; centre it at x y with radius r .
Maybe you need to clarify your problem.
|
|
|
|
|
I am using DrawEllipse to create my circle. This creates a circle within a rectangle and counts the starting position as the top left of the rectangle. It then draws to the right and down to create the circle.
MSDN information for this states: DrawEllipse(Pen, Single, Single, Single, Single) - Draws an ellipse defined by a bounding rectangle specified by a pair of coordinates, a height, and a width.
This is the relevant code:
Dim penCharacterCircle as Pen
Dim gfxCharacterCircle as Graphics
Dim MousePositionX as Integer = Cursor.Position.X - 35
Dim MousePositionY as Integer = Cursor.Position.Y - 55
penCharacterCircle = New Pen(System.Drawing.Color.Green, 6)
gfxCharacterCircle.DrawEllipse(penCharacter, MousePositionX, MousePositionY, 50, 50)
|
|
|
|
|
Assuming that the above is working, I still don't understand what your problem is. Please try and explain exactly what you are trying to do, what results you expect, and what results you see.
|
|
|
|
|
The above draws a circle from the cursor positions, both X and Y coordinates, and then moves the starting point of the circle to the top left by the -35(X) and -55(Y) I used as offsets. This does work properly. What doesn't work are some other circles which are of differing sizes, dependent on a variable.
If I want each secondary circle to be concentric with the first one, I have to manually enter in the values. An example would be: first circle is size 50, second one is 100. When I click, it places the first circle centered around the mouse, equidistant from the clicked point. It then places the second circle. If I don't enter an offset, it places the circle to the bottom right of the clicked point.
I can manually enter an offset so it puts the second circle in the right place, but I have many different sized circles. Each one requires a different offset. This is caused by it drawing the circle from the top left to the bottom right, instead of from the center. It draws it like a rectangle.
I want it to draw the circle from the center, so I don't have to figure out offsets for all of the different sized circles.
|
|
|
|
|
ChrisDScott93 wrote: This is caused by it drawing the circle from the top left to the bottom right, instead of from the center. It draws it like a rectangle.
Yeah, computers are such contrary so-and-sos. Your problem is merely one of mathematics, given the centre and radius of your circle you need to calculate the offset and size of its containing rectangle. If you write a function that does just that then you should be able to draw any size circle at any point in your window. Given that the circle's radius is equal to half the width and height of the rectangle the starting point should be:
Origin = centre.x - Radius, centre.y - Radius
You may also need to adjust for the X:Y ratio unless you are able to set one of the mapping modes which does it automatically (my VB skills are very basic).
|
|
|
|
|
A circle with a center (xc, yc) and radius r1 will span from (xc-r1,yc-r1) to (xc+r1,yc+r1).
And similar formula apply for radius r2.
I can't start to imagine where your problem would be, unless you use Graphics.TranslateTransform and start accumulating those translations.
If you do use those Transform methods in a method, it is wise to also undo the matirx transformations before exiting the method.
modified 24-Sep-11 11:07am.
|
|
|
|
|
I will be honest here, I am just starting out on doing this, and I have not yet become familiar with Graphics.TranslateTransform.
I do not see a way to allow the circle to be created using a radius, but I may just be overlooking something very simple.
Please see my reply to OriginalGriff for a code sample.
|
|
|
|
|
I guess you did not notice that my name is not OriginalGriff!
|
|
|
|
|
Hi not OriginalGriff, how are you today?
|
|
|
|
|
Heh, I saw the link at the bottom of Richard MacCutchan's reply. I was referring to Richard with my comment. Sorry for the confusion!
|
|
|
|
|
I am not OriginalGriff, I am a free man!
|
|
|
|
|
What I said earlier boils down to
gfxCharacterCircle.DrawEllipse(penCharacter, MousePositionX-radius, MousePositionY-radius, radius, radius)
Rationale: all Graphics operations take the top LHS corner as the reference point, DrawEllipse does not want the center point!
modified 24-Sep-11 13:18pm.
|
|
|
|
|
Is there something I can use that does take the center, instead of the top left?
|
|
|
|
|
a sheet of paper and a pair of compasses.
|
|
|
|
|
I thought this might have fixed it, but it does not.
I did do some testing though, and discovered that the offset is directly related to the size of the Form. However, this has not helped me much.
I have my monitor resolution at 1440x900 and the Form size is the same.
I tried:
YRadius - (900 / YRadius) and XRadius - (1440 / XRadius) to create the offset.
Then I draw the circle using:
gfxCharacterCircle.DrawEllipse(penCharacter, MousePositionX-Xradius, MousePositionY-Yradius, radius, radius)
It is still not placing the circle's center directly on the mouse though.
I must say, this is the most frustrating thing in the world right now. I will admit, my math is a bit rusty, but I didn't think it was this bad...
|
|
|
|
|
i am looking for a code to Print preview and print listview in printer in vb.net or 2008.please assist.thanks.
|
|
|
|
|
As far as I'm aware, you can't print a listview directly. What you want to do is use printdocuments.
Google search[^]
Try those, and let us know if you have any further questions.
|
|
|
|
|
Try
m_SelectedStyle = New DataGridViewCellStyle()
m_SelectedStyle.BackColor = Color.LightBlue
m_SelectedStyle.BackColor = SystemColors.Highlight
DataGridView1.ReadOnly = True
Dim SQLString As String = "SELECT id, bedrijfsnaam, startdatum, vervaldatum, omschrijving, netto, bruto, opmerkingen FROM Facturen"
Dim DataSet As New DataSet()
Dim OleDbDataAdapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, oleConn)
oleConn.Open()
OleDbDataAdapter.Fill(DataSet, "Facturen")
DataGridView1.DataSource = DataSet.Tables("Facturen")
'here the colors starts
DataGridView1.Rows(1).DefaultCellStyle.BackColor = Color.Blue
Dim vandaag As String = Today
Dim i As Integer = 0
For Each row As DataGridViewRow In DataGridView1.Rows
If DataGridView1.Item(2, i).Value() = vandaag Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.IndianRed
ElseIf DataGridView1.Item(2, i).Value() > vandaag Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
End If
i = i + 1
Next
DataGridView1.AutoResizeColumns()
oleConn.Close()
Catch ex As Exception
blabla
End Try
Even if i try to just color without conditions it doesnt work something like:
DataGridView1.Rows(2).DefaultCellStyle.BackColor = Color.LightGreen
But whyyyyy....
|
|
|
|
|
Hi,
1.
that is unreadable; use PRE tags to get a non-prop font and proper indentation.
2.
don't swallow exceptions, they provide useful information.
3.
in my experience, DGV backcolor only works on non-empty cells. My "CP Vanity" article uses it a lot (it is C#, doesn't really matter).
|
|
|
|
|
1. True.
2. True.
3. Not True.
|
|
|
|
|
The last one is indeed not true...
For your first 2 points thx 4 the advice...
So my code between pre thags(sorry 4 that)
m_SelectedStyle = New DataGridViewCellStyle()
m_SelectedStyle.BackColor = Color.LightBlue
m_SelectedStyle.BackColor = SystemColors.Highlight
DataGridView1.ReadOnly = True
Dim SQLString As String = "SELECT id, bedrijfsnaam, startdatum, vervaldatum, omschrijving, netto, bruto, opmerkingen FROM Facturen"
Dim DataSet As New DataSet()
Dim OleDbDataAdapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, oleConn)
oleConn.Open()
OleDbDataAdapter.Fill(DataSet, "Facturen")
DataGridView1.DataSource = DataSet.Tables("Facturen")
'here i do the code to check if a field is smaller then a certain date
Dim vandaag As String = Today
Dim i As Integer = 0
For Each row As DataGridViewRow In DataGridView1.Rows
If DataGridView1.Item(2, i).Value() > vandaag Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.IndianRed
ElseIf DataGridView1.Item(2, i).Value() < vandaag Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
End If
i = i + 1
Next
oleConn.Close()
I hope is more clear now
Thx 4 the answers already
greetz
|
|
|
|
|
That's because you got a bounded datagridview.
If you want colors, you'll need to put it in a CellFormatting Sub, like so:
Public Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
End Sub
|
|
|
|
|