|
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
|
|
|
|
|
The celformatting is updating all the time...
I think it's not a good practice 4 memory use etc...
If i place a messagebox in the sub's it's popping up all the time...
Anyway Thx
greetz
|
|
|
|
|
Ofcourse it is. It's like a Paint routine on a Form, Panel, etc.
Therefore it is not a good idea to put a messagebox in there, just do your coloring.
|
|
|
|
|
Correction: The issue is not the resizing as the resized photos view fine outside of the report. The issue appears moreso to be that when the image is stored in a datatable and put into a crystal report via binary stream, it comes out pixelated. Is there a method to store those in the datatable and transfer them to CR in a less pixelated manner?
I use the following function to resize an image that gets merged into a crystal report to make a photo book.
Private Sub importPhoto(ByVal strFileName As String, ByRef Width As Int32, ByRef Height As Int32, ByVal saveLocation As String, ByRef objDataRow As DataRow)
Dim imgPhoto As New Bitmap(strFileName)
Dim sourceWidth As Int32 = imgPhoto.Width
Dim sourceHeight As Int32 = imgPhoto.Height
Dim sourceX As Int32 = 0
Dim sourceY As Int32 = 0
Dim destX As Int32 = 0
Dim destY As Int32 = 0
Dim nPercent As Single
Dim nPercentW As Single
Dim nPercentH As Single
'If Not File.Exists(saveLocation & "\" & Path.GetFileName(strFileName)) Then
nPercentW = Width / CSng(sourceWidth)
nPercentH = Height / CSng(sourceHeight)
If nPercentH < nPercentW Then
nPercent = nPercentH
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2)
Else
nPercent = nPercentW
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2)
End If
Dim destWidth As Int32 = sourceWidth * nPercent
Dim destHeight As Int32 = sourceHeight * nPercent
Dim bmPhoto As New Bitmap(Width, Height, PixelFormat.Format24bppRgb)
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)
Dim g As Graphics = Graphics.FromImage(bmPhoto)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.Clear(Color.White)
g.DrawImage(imgPhoto, New Rectangle(destX, destY, destWidth, destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel)
g.Dispose()
imgPhoto.Dispose()
bmPhoto.Save(saveLocation & "\" & Path.GetFileName(strFileName), Imaging.ImageFormat.Jpeg)
Dim fs As New FileStream(saveLocation & "\" & Path.GetFileName(strFileName), FileMode.Open, FileAccess.Read)
Dim Image(fs.Length - 1) As Byte
fs.Read(Image, 0, Convert.ToInt32(fs.Length))
fs.Close()
objDataRow(11) = Image
File.Delete(saveLocation & "\" & Path.GetFileName(strFileName))
GC.Collect()
'Else
' Dim fs As New FileStream(saveLocation & "\" & Path.GetFileName(strFileName), FileMode.Open, FileAccess.Read)
' Dim Image(fs.Length - 1) As Byte
' fs.Read(Image, 0, Convert.ToInt32(fs.Length))
' fs.Close()
' fs.Dispose()
' objDataRow(11) = Image
' Image = Nothing
' GC.Collect()
'End If
End Sub
Ignoring the commented out parts, the issue is that while the picture does come out at the desired size, it becomes very pixelated. Is this a result of the graphics interpolation mode? Or is there a better method of doing this? The issue is that I get large resolution pictures (2816 x 2112) that end up in a 300 x 200 box in the report. This makes the report giant and time consuming (It is 12,000 pages to begin with) so I shrink the pictures down to a more manageable size in order to speed up performance.
Anyone have an opinion on this?
Cheers, --EA
modified 22-Sep-11 12:21pm.
|
|
|
|
|