|
Are you performing some transformations, as in Graphics.ScaleTransform() and many others?
What is the size of your Bitmap?
jensenx wrote: Or the way i'm saving it into the bitmap?
You are not really saving to bitmap, you are drawing inside the Bitmap, aren't you?
You might consider showing the entire bitmap creation, graphics and drawing method,
as well as the Paint handler.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yup, i'm drawing it into bitmap
Here goes,
Private Sub DrawBars_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pnl_Chart.Paint<br />
e.Graphics.Clear(Color.White)<br />
<br />
If chart_NoChange = False Then<br />
chart_NoChange = True<br />
new_snapshot = New Bitmap(pnl_Chart.Size.Width, pnl_Chart.Size.Height, pnl_Chart.CreateGraphics())<br />
<br />
drawBarChart()<br />
<br />
e.Graphics.DrawImage(new_snapshot, 0, 0)<br />
e.Dispose()<br />
<br />
Else<br />
e.Graphics.DrawImage(new_snapshot, 0, 0)<br />
e.Dispose()<br />
End If<br />
<br />
End Sub<br />
<br />
Public Sub drawBarChart()<br />
<br />
Dim brush_Handle As Integer = 1<br />
Dim strText As String<br />
Dim clearForm As Boolean = True<br />
<br />
Dim grfx As Graphics = pnl_Chart.CreateGraphics()<br />
<br />
'TEST DRAW ON BITMAP<br />
grfx = Graphics.FromImage(new_snapshot)<br />
<br />
Dim yCenter As Integer = (bar_Height / 2)<br />
<br />
<br />
'Draws today's line<br />
If chk_ShowTodayLine.Checked = True Then<br />
Dim x As Integer = get_xLocation(Date.Today.Date) + (grid_Width / 2)<br />
grfx.DrawLine(Pens.Blue, x, 0, x, pnl_Chart.Height)<br />
End If<br />
<br />
'Draw project's end date<br />
If grid_EndDate <> "" Then<br />
Dim x As Integer = get_xLocation(grid_EndDate) + (grid_Width)<br />
grfx.DrawLine(Pens.Red, x, 0, x, pnl_Chart.Height)<br />
<br />
End If<br />
<br />
Dim arrayLoc As Integer = 0<br />
While arrayLoc <> grid_Task.Rows.Count<br />
<br />
'Normal chart from arraytable-----------------------------------------------------<br />
If arrayTable(arrayLoc).Duration <> 0 Then<br />
'Set values<br />
Dim x1 As Integer = arrayTable(arrayLoc).xLocation<br />
Dim y1 As Integer = arrayTable(arrayLoc).yLocation<br />
Dim bar_Width As Integer = (grid_Width * arrayTable(arrayLoc).Duration)<br />
<br />
'Draw Rectangle<br />
grfx.DrawRectangle(Pens.Black, New Rectangle(x1, y1, bar_Width, bar_Height))<br />
'Highlight selected<br />
If selectedRow = arrayLoc Then<br />
'Fill Rectangle<br />
grfx.FillRectangle(Brushes.Black, New Rectangle(x1 + 1, y1 + 1, bar_Width - 1, bar_Height - 1))<br />
Else<br />
'the +1 and -1 are there to display the rectangle nicely<br />
grfx.FillRectangle(objColorArray(brush_Handle), New Rectangle(x1 + 1, y1 + 1, bar_Width - 1, bar_Height - 1))<br />
<br />
End If<br />
'Display Text and Values<br />
strText = "(" & arrayTable(arrayLoc).estimated_StartDate & "," & arrayTable(arrayLoc).Duration & ")"<br />
grfx.DrawString(strText, New Font("VERDANA", 7.0, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, (x1 + bar_Width + line_Width), y1 + yCenter - 6)<br />
<br />
brush_Handle += 1<br />
'If goes more than 150 colors been used<br />
If brush_Handle > objColorArray.GetUpperBound(0) Then<br />
brush_Handle = 1<br />
End If<br />
Else<br />
'Those not assigned rows....<br />
End If<br />
'End Normal chart from arraytable--------------------------------------------------<br />
<br />
<br />
<br />
arrayLoc += 1<br />
End While<br />
<br />
<br />
grfx.Dispose()<br />
<br />
<br />
<br />
End Sub<br />
Sorry for the mess! I would gladly clarify parts of my code if it needs to be
|
|
|
|
|
Hi,
I am not sure what is causing the problem; here are some remarks:
1.
you call Dispose() on PaintEventArgs, which is wrong: you did not create that event, nor
did you call a method that creates it, so you should not dispose of it, it is not yours at all.
2.
you don't call Dispose() on new Font(...) in DrawString(...); here you did
ask for the creation and you don't Dispose(); that's a memory leak. If it's only one font
that you need regularly, you might want to create it once and keep it in a class member.
3.
you don't call Dispose() on pnl_Chart.CreateGraphics() in new Bitmap(...); here you did
ask for the creation and you don't Dispose(); that's a memory leak. A Graphics is a big
object, older Windows only can handle a few of them, so you really should dispose() of it.
4.
you explicitly specify GraphicsUnit.Point in new Font(...); although it seems correct,
I have never used it. Try omitting that argument. font sizes are in points by default.
Apart from these, I could not see anything wrong and causing the effects you described.
BTW: why do you show code in CODE tags? it would read much easier in PRE tags!
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi again!
Thx for your response. I've looked into those areas you have highlighted and made necessary changes.
One for instanc; instead of calling a new Font everytime, ive Dim verdanaFont as New Font ("VERDANA",7.0), is this right?
Cause im still having the same problem
I would appreciate if someone could write up a simple app to have the same concept of drawing the string into a bitmap then later painting the bitmap onto screen.
Oh and about using 'code' instead of 'pre', im still quite new around here. I've wanted to paste my codes in, and by looking at the formatting available below, the word code stands out, even more when its in red. Will use pre next time!
Thanks in advance!
Regards,
jensen
|
|
|
|
|
A quick alteration!
i've managed to solve the problem by writing the codes a lil differently but using the same concept....dont know why this new way works....
but anyhow
Cheers!
regards,
jensen
|
|
|
|
|
I'm having problems w/the following code. It doesn't seem to update my Access database. Thanks in advance for your help.
---
Option Explicit On
Imports System.Data
Imports System.Data.Oledb
Public Class frmAddCompany
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim strProvider As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Environment.CurrentDirectory & "\testDb.mdb"
Dim strSQL As String = _
"select * from company"
Dim myDbConn As OleDbConnection
Dim myDataAdapter As OleDbDataAdapter
Dim myDataSet As DataSet = New DataSet
Dim myDataTable As DataTable = New DataTable
myDbConn = New OleDbConnection(strProvider)
myDataAdapter = New OleDbDataAdapter(strSQL, myDbConn)
myDataAdapter.Fill(myDataSet, "Company")
myDataAdapter.Fill(myDataTable)
Dim myDataRow As DataRow = myDataTable.NewRow()
myDataRow("CompanyName") = "test123"
myDataTable.Rows.Add(myDataRow)
myDataSet.Tables("Company").AcceptChanges()
myDataAdapter.Update(myDataSet, "Company")
myDbConn.Close()
End Sub
End Class
|
|
|
|
|
Are you getting an error message? Could you please display it for us to see, if you are? Is the CompanyName the only column in the Company table? You don't seem to have any checks to make sure CompanyName is unique, this could lead to problems in the future.
For one thing, I don't think you need this statement:
myDataSet.Tables("Company").AcceptChanges()
Because it sets the changed flag on the rows in the table. Then when you do your update it doesn't think it's changed so it won't update it.
Hope this helps.
|
|
|
|
|
I put a Stop in my code so that I can view the contents of a local datatable. Is there a way to view the data in a datatable in a browse window, like an excel spread sheet allowing you to see all rows and columns at once?
|
|
|
|
|
I'll assume by Stop you mean a breakpoint...and if you have visual studio 2005 then it is pretty simple. All you have to do is set your breakpoint to stop sometime after your datatable has been filled, when it hits the breakpoint highlight the table name in your code and then hover your mouse over it. When a little icon appears that has a magnify glass, click on it. A popup will open that displays your data in a nice grid. Another way is to highlight the table name, right click and select QuickWatch. There you can click on the magnify glass icon at the top of the list of properties to look through. If you do not have visual studio 2005 I don't know of a nice way to view the data, short of writing some code to output it to a csv file to view in excel.
|
|
|
|
|
Hi does anyone know if there are problems with microsoft at the moment. all of a sudden when I enter the dataset configuation I'm getting thrown out and now it's even happening when I try and edit the dataset. various prompts including "microsoft has come encountered a problem and needs to close.
I've checked the problem and seems to be APPCRASH.
Can anyone help me please?
Nala
|
|
|
|
|
hi everyone,
i have a listbox which contain some item .now i want to change the content of selected item with new string as shown below
lstCaptionStructure.SelectedItem.ToString.Replace(lstCaptionStructure.SelectedItem.ToString, NewString)'lstCaptionStructure is list box
but above code does not work.can any body tell where i am wrong or how can we change the some or full part of selected item with other string ?
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
Hi,
if you have a collection of things and want to replace one of those things, you must
operate on the collection, hence something along the lines of:
lstCaptioStructure.Items(lstCaptioStructure.SelectedIndex)=NewString
Items is the collection here.
BTW this code would bomb if nothing is selected (as would your code)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
thanks luc ,
its work
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
http://www.codeproject.com/cs/miscctrl/winwordcontrol.asp
I am using this control in my application. It works fine for the first time but every time after that (until we exit application and restart it ) instead of loading word inside the control it is loaded as a separate application. i have debugged the code (load document method) many times but there is no problem and all statements execute fine. one change i have made in the code is the closecontrol method and the change is
public sub closecontrol()
Dim dummy As Object = Nothing
Dim rcw As Object = Nothing
If wd.Documents.Count > 0 Then
wd.Documents.Close(dummy, dummy, dummy)
Marshal.FinalReleaseComObject(wd.Documents)
End If
wd.Quit(dummy, dummy, dummy)
rcw = wd
wd = Nothing
Marshal.FinalReleaseComObject(rcw)
deactivateevents = False
document = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
wd = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
end sub
i call this method when closing the form on which this control is placed.
please let me know if you have any idea about this problem
Salman Sheikh
|
|
|
|
|
Salman Sheikh wrote: http://www.codeproject.com/cs/miscctrl/winwordcontrol.asp
Go to that article and ask the author for help. There is a message board at the bottom.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Use VB2005
I have "Class1.vb" and "Form1.vb", "class1.vb" contain in my Text and want to show in "Form1.vb" ,How to implement it?
thank you
|
|
|
|
|
your question seems to be unclear .. please ask clearly what you want to do
Salman Sheikh
|
|
|
|
|
Sorry, I contain text in class1. and how to get text form class1? now i working in Form1
|
|
|
|
|
if u mean u want the text in the label to appear on the form caption, then you say
form1.text = label1.text
if u want the file under the solution explorer called form1.vb to be called class1.vb then make sure u change the one thats called class1.vb currently to something else then click form1.vb and rename it to class1.vb
otherwise if thats not wat you want to do then u need to re-phrase your question and make it a bit clearer, its a bit confusing
|
|
|
|
|
First of all, give your classes meaningful names. Then, it depends. Is code being called in the class, which needs to send text to the form ? Use a delegate in this situation, the odds are that the class does not contain an instance of the form. If the form is being called and needs to pull the text, then myTextBox.Text = myClassInstance.TheText will do it, where TheText is a property you define. You could also return it from a method, if this is appropriate.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi guys,
I am writing a system that should connect to varied database systems (currently MS SQL 2000, 2005 and MySQL). I decided to use Oledb.net provider for my connections. For the different versions of MSSQL it works fine but I am having a problem trying to run commands on MySQL connection. I got the following connection string from the net
Dim myCommand As New OleDbConnection("Provider=MySqlProv.3.0;Data Source=th911;User Id=root;password=root")
From my analysis of the connection string there is no database name (Initial Catalog). How then does MySQL know the database i am interested in or how can i make it known without having to enter the credentials every time i open the connection?
Thanks for your assistance guys.
-Mbire-
I can resist everything else except temptation...
-- modified at 8:24 Monday 10th September, 2007
|
|
|
|
|
Mbire wrote: How then does MySQL know the database i am interested in or how can i make it known without having to enter the credentials every time i open the connection?
You will need to specify the database name. http://www.connectionstrings.com[^] has many different database connection strings that you might find helpful.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
What is there to elaborate? The value of the townId is in the ComboBox's SelectedValue property. That's the value that you update the Person's record with.
Where's the problem?
|
|
|
|
|
Helo dear!
I want to install two projects and two third party softwares with one setup programme. want to start one project wait to complete then start another but fails. please help me.
I will be grateful
Julian
|
|
|
|
|
I have an mdb file that has vb code in my PC. I want other users to use it from their PCs'. But a copy the file should not work on their PCs'. I can not check it with any hardware ids' because each instance would run diffent h/w ids in different PCs'. What else is left for me as options?
|
|
|
|
|