|
Hi,
here are two bits of information for you:
1.
there are several relevant articles here on CodeProject (e.g. search for Paint.NET)
2.
I have a standard reply for such questions, here it goes (example code is C#, VB.NET would be similar):
there are several steps to correctly draw something; it does not matter how complex the paint job is: from a single line, to a complex drawing, or a real work of art.
To make sure it all becomes visible on the screen and gets repainted automatically when moving, resizing, minimizing/maximizing/restoring or uncovering your Form, one should follow these steps:
1.
decide upon what object you want to draw; it normally is a Control (e.g. a Panel) or a Form itself. I prefer to add a Panel to a Form, then draw on the Panel. And I do not like PictureBoxes, they are pretty useless.
2.
create some variables (Rectangle, struct, class, whatever) that hold the parameters of your drawing. For a rectangle that could be top and left coordinate, and width+height, or just a Rectangle. etc. For a complex drawing, it could be a List of objects that derive of a common type, each having its own PaintMe() method.
3.
create a Paint handler (either add your own paint handler to the Paint event, or override the OnPaint method) for that Panel, and do all your drawing in there, using the Graphics object inside the PaintEventArgs, and your variables. Do not call CreateGraphics!
4.
if and when you want to change things, modify the variables and call Panel.Invalidate() or one of its overloads (for selective invalidation).
5.
If you want to animate things, perform the move (step 4) inside the Tick handler of a Windows.Forms.Timer which ticks on the GUI thread, so you are allowed to call Invalidate() from there too.
BTW: if you need to create some objects (Fonts, Pens, Brushes, ...) either keep them
alive in class members (hence create them only once); or create them inside the Paint
handler and don't forget to call Dispose() on them.
C# example:
private Panel panel;
private bool paintRectFlag=true;
private Rectangle rect=new Rectangle(20, 20, 300, 200);
private Pen rectPen=Pens.Black;
public Form1() {
InitializeComponents();
panel=new Panel();
panel.Bounds=new Rectangle(…);
panel.Paint+=panelPaintHandler;
Controls.Add(panel);
}
protected void panelPaintHandler(object sender, PaintEventArgs e) {
Graphics g=e.Graphics;
if (paintRectFlag) g.DrawRectangle(rectPen, rect);
}
protected void buttonClickHandler(object sender, EventArgs e) {
paintRectFlag=!paintRectFlag;
panel.Invalidate();
}
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
hi,
i have lot of doubt in crystal report.
i have taken printout in 10*12 size paper.
how we can mention paper size in pragmatically ??
another one doubt i have taken printout for billing purpose.if we are going to take morethan one page, total amount is printing every page.
i dont need to print total amount in every page only last page.
plz help me very urgent
Yours,
KaNNaN
-----------------------------------------------------------------
"Success is When Ur Signature Becomes An Autograph"
Mail To : foreverkans@gmail.com
modified on Monday, August 24, 2009 3:06 AM
|
|
|
|
|
Hi,
I like to change the Startmode of a service in a Windows Forms application using Visual basic.
I tried the following code:
I do not get a error, but the StartMode does not change.
Try
Dim class1 As ManagementClass = New ManagementClass("Win32_Service")
For Each ob As ManagementObject In class1.GetInstances
If ob.GetPropertyValue("Caption").ToString = Me.cbservices.SelectedItem.ToString Then
If ob.GetPropertyValue("StartMode") = "Disabled" Then
ob.SetPropertyValue("StartMode", Me.cbStartMode.Text)
Exit Sub
End If
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Does anybody have an idea?
Thanks in advance for your help!!!!!
Dennis
|
|
|
|
|
Hi,
when getting info from WMI one tends to call ToString to show it;
in VB.NET this isn't even necessary, it will happen implicitly.
When setting info through WMI the type must be correct, StartMode isn't a string, it is a ServiceStartMode value.
Hence:
1. add a reference to System.ServiceProcess
2. do something like (not tested):
ServiceStartMode mode=ServiceStartMode.Parse(Me.cbStartMode.Text)
ob.SetPropertyValue("StartMode", mode)
alternatively add real ServiceStartMode values to the combobox, that would avoid the parsing.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks.
I will try today and let you know the result.
Dennis
|
|
|
|
|
Thanks,
It workes like a charm.
Dennis
|
|
|
|
|
I am using VB6 Sp6 and Crystal Reports 8 in my application ,sql server 2000 in the backend. I am having a problem that if i execute a report i am having problem in the output once in a week but most of the time i am not getting any problems.If i again close and open the report output is correct.I am executing a view from my front end . if i check with query in the view, data is coming fine. In application, data are grouped together by using a Account Number in crystal reports.i am uanble to find any problem can you advice me on this. I need your help.
|
|
|
|
|
Why are you still using VB6 ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Just go to your crystal report report and to file menu there will be a check box that Save Data with report just remove check , problem will be solved
Best Of Regards,
SOFTDEV
Sad like books with torn pages, sad like unfinished stories ...
|
|
|
|
|
I’m working on a project that saves records to a datatable/dataset. I then serialize the dataset to save it, and deserialize to show the records in a datagridview, and I add more records, serialize, deserialize etc etc. – I’m using binary formatting. I added the dataset/datatable from the toolbox and selected “untyped” for the dataset.
I want to print out this table and other text.
Do I need to draw a report using graphics on to a page and then programmatically add the data from the deserialized file, or is there a better way to design and add data to a report? I’ve looked at crystal reports and report viewer and I cannot see how to programmatically add data using them – they both talk about connecting to a SQL or ADO database which mine isn’t.
Any help and/or any tutorials about this would be appreciated.
Regards,
Steve
Thanks for your help and advice!
Steve
|
|
|
|
|
First thing is to go get a hammer, now bash your left foot with it, the pain you feel is nothing to what you will feel if you decide to use Crystal Reports. There are a number of threads here discussing reporting tools, none recommend CR.
As you are not even using a database I assume your data requirements are minimal (serializing datasets will very quickly become useless if you have any real volume of data) so depending on the VS version there are report projects/forms you can add. Also there are grid printing articles on CP I believe .
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Mycroft,
Yes, I agree with your crystal reports idea!!!! - it definitely is too much for this project. Yes, the data requirements are minimal and yes, I'm not using a database - I put records into a datagrid view and then serialize when finished.
I'm using using VS 2008 full version.
Could you point me in the direction of any articles/help/other threads/sites on this subject please
I'm a beginner hobby programmer and know only a little but feel I've made good progress so far..... I've got this vision where it's possible to placce a piece of blank paper onto a form and then drag n drop the various objects onto it, ready for printing but I'm realising that probably isn't possible. (it's a good idea for an expert to design a class like that...!!!!).
So could you give me some pointers in the direction I need to go....?
Regards,
Steve
Thanks for your help and advice!
Steve
|
|
|
|
|
Seems to be plenty of articles[^] here to cover the subject.
|
|
|
|
|
Hi All,
I have a Label and A Picturebox. Picturebox have a image.
Label Backcolor is Transparent.
When i am tring to drag Label in Over of Picturebox. Label Backcolor shows Forms Color.
But i want to get background Image which is in Picture box.
Thanks for help
If you can think then I Can.
|
|
|
|
|
Pick a Panel , set it's backgroundpicture to whatever picture was shown in the PictureBox . Next, drag a label to that panel and set it's backgroundcolor to "Transparent" (webcolor).
There you go, a transparent label
I are Troll
|
|
|
|
|
Thanks Dear,
but my requirement is changing and Draging of Picturebox.
So obviously background will be changed.
So Please give me another idea.
If you can think then I Can.
|
|
|
|
|
Add this to the OnPaint handler of your PictureBox;
public Form1()
{
InitializeComponent();
foreach (Control ctl in this.Controls)
if (ctl is Label)
{
Label lbl = (Label)ctl;
lbl.Visible = false;
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
foreach (Control ctl in this.Controls)
if (ctl is Label)
{
Label lbl = (Label)ctl;
e.Graphics.DrawString(
lbl.Text,
lbl.Font,
new SolidBrush(lbl.ForeColor),
lbl.Left - pictureBox1.Left,
lbl.Top - pictureBox1.Top);
}
}
eg_Anubhava wrote: So Please give me another idea.
This hides the labels during runtime, and uses the Paint-handler to write the text onto the forms' canvas
eg_Anubhava wrote: but my requirement is changing and Draging of Picturebox.
The PictureBox itself, or the controls inside it? The Panel that I referred to also has support for drag & drop.
Good luck
"Sometimes glass glitters more than diamonds because it has more to prove"
--Terry Pratchett
|
|
|
|
|
Hello Eddy Vluggen,
Thanks for reply.but
You are trying to create text on picture box.but my concept says show picture in label when i m draging and moving label around picturebox.
If you can think then I Can.
|
|
|
|
|
I'm sorry, but both Label as well as the PictureBox have their limitations. The second solution that I posted removes the Label entirely, and you can't click (or drag) what isn't there.
Unfortunately, I don't know how to achieve the requirements of your concept.
I are Troll
|
|
|
|
|
Hello To All
i am having a hard time here
what i am trying to do it when you check the check box and status is not connected it will display a msg me saying the error messages like Interface is not pluged in
this is my problem i got it to work with the IF but you check the boc get the error boc click on and the check box is checked i dont want it checked if the satus is not connected so i put CheckBox1.Checked = False that worked but now i get the error msgbox 2 times i no why when it taked the check box out it runs the IF code lines agine
Is thare anyway to fix this of some other thing i can google and look up ???
Thanks in advance
Bob
<br />
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged<br />
If Status.Text = "Not Connected" Then<br />
MsgBox("Interface is not pluged in", MsgBoxStyle.OkOnly + vbCritical, "Error")<br />
CheckBox1.Checked = False<br />
<br />
Else<br />
'The Code to Run My Program '<br />
End If<br />
End Sub<br />
|
|
|
|
|
Set a form level flag before you do the check bChecking to true, inside your event code return if the flag = true, this will short circuit the recursive loop. Then the last line (after setting the checkbox) set bChecking to false so it is ready for the next event. Something like the following
Private bool bChecking
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
if bCheckeing then return
bchecking = true
If Status.Text = "Not Connected" Then
MsgBox("Interface is not pluged in", MsgBoxStyle.OkOnly + vbCritical, "Error")
CheckBox1.Checked = False
bchecking = false
Else
'The Code to Run My Program '
End If
End Sub
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Mycrott
I am pretty sure i got it to work the way i wanted just have to do more testing when i get home tonight
Once agine your help is Greatly appreciated
Thanks
Bob
|
|
|
|
|
Ok i tested it and that part you showd me works perfect now i have a other problem
When click the check box with the device not conectted i get the error msg box and the check do not stay thare that part works good
When click the check box with the device conectted it runs the code
If CheckBox1.Checked Then
NumericUpDown1.Value = CType(CTemp.Text, Integer) + 1
NumericUpDown2.Value = CType(CTemp.Text, Integer) - 1
and it works
But when you click to take the check out of the check box it will not run this code
Else
NumericUpDown1.Value = 0.0
NumericUpDown2.Value = 0.0
phidgetIFK.outputs(0) = False
phidgetIFK.outputs(1) = False
End If
witch it was working before i put the bChecking
Private Sub CheckBox1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If bChecking Then Return
bChecking = True
If Status.Text = "Not Connected" Then
MsgBox("interface is not connected. Connect USB cable and try agine.", MsgBoxStyle.OkOnly + vbCritical, "Error")
CheckBox1.Checked = False
bChecking = False
Else
If CheckBox1.Checked Then
NumericUpDown1.Value = CType(CTemp.Text, Integer) + 1
NumericUpDown2.Value = CType(CTemp.Text, Integer) - 1
Else
NumericUpDown1.Value = 0.0
NumericUpDown2.Value = 0.0
phidgetIFK.outputs(0) = False
phidgetIFK.outputs(1) = False
End If
End If
End Sub
Thanks for every ones help
|
|
|
|
|
I need to know how to make buttons and other objects move to the center of the form and possibly grow in size when form is maximized and also move back to its position when minimized. Please I need fast response house
|
|
|
|
|
tolmega01 wrote: Please I need fast response house
That is almost certain to slow any replies. If it is that urgent, get your credit card out and visit rentacoder.com
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|