|
Your code is messed up to say the least. You can start by removing every line that says "CreateGraphics" and replace it with this:
Dim g As Graphics = e.Graphics
Use the Graphics object passed to you in the event args. Do NOT create your own Graphics object when handling Paint events.
Get rid of your OnPaint method.
You're creating objects all over the place, but only Diposing of some of them. Your code leaks resources like mad because your creating these objects on every Paint event call, but never releasing them. You'll eventually run the system out of resources and Windows will start behaving very strangely. Create objects that do not change over time, like brushes, pens, and fonts, once, and reuse them. Dispose of them when you app closes.
|
|
|
|
|
When I used this code
<pre>Dim g As Graphics = e.Graphics</pre>
Its gives me error at run time that:
Parameter is not valid
|
|
|
|
|
Where are you putting the code? You need to put that code in a Paint event or any function that has a PaintEventArgs Parameter. If you start a new project and put this in the Form1_Paint event like this
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = e.Graphics
g.DrawString("Hello, World !", New Font("Verdana", 15), New SolidBrush(Color.Red), New PointF(20, 20))
g.DrawString("This is an example of using a Paint event", New Font("Arial", 12), New SolidBrush(Color.Blue), New PointF(20, 50))
g.Dispose()
End Sub
you shouldn't have any problems.
|
|
|
|
|
Dear Following is my code and below that is the error I get:
<pre>Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.IO
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = e.Graphics
g.DrawString(TextBox1.Text, New Font("Verdana", 15), New SolidBrush(Color.Red), New PointF(20, 20))
g.DrawString(TextBox1.Text, New Font("Arial", 12), New SolidBrush(Color.Blue), New PointF(20, 50))
g.Dispose()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
e.KeyChar = ChrW(AscW(CommonFunctions.AsciiToUnicode(AscW(e.KeyChar))))
End Sub
Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
Dim g As Graphics = e.Graphics
g.DrawString(TextBox1.Text, New Font("Verdana", 15), New SolidBrush(Color.Red), New PointF(20, 20))
g.Dispose()
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Refresh()
End Sub
End Class</pre>
<b>Error I get</b>
<
System.ArgumentException was unhandled
Message="Parameter is not valid."
Source="System.Drawing"
StackTrace:
at System.Drawing.Graphics.GetHdc()
at System.Drawing.BufferedGraphics.RenderInternal(HandleRef refTargetDC, BufferedGraphics buffer)
at System.Drawing.BufferedGraphics.Render()
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Label.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at DrawStringMethodGDI_.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
>
|
|
|
|
|
I still cannot see what you are trying to do, nor do I know where in the program you are getting the error. Is it when the form is loading, when you type in the textbox , where? Have you made sure that you have put text in the textbox before the form is loaded? Comment out the label_paint, and textbox_keypress events and try running it again. Did you try my example I gave you with strings instead of TextBox1.Text, and what results did that give you ?
|
|
|
|
|
ok I found out the problem that it gives error bcoz of the g.dispose() in the label's paint sub.
but its not showing anything in label
|
|
|
|
|
Having read up a little bit on it, it seems that this catches a lot of people out. According to MSDN, it is only good practice to Dispose of your Graphics object if you specifically Create it, and not if you receive it from another routine, such as in your control.Paint PaintEventArgs parameter. This is because there might be other routines further down the line that need that object. So there is no reason to dispose of your graphics object in this case. As to why it is not painting in the label, there is nowhere where you paint anything to the label
|
|
|
|
|
Your still not disposing the other GDI objects you're creating, like Brush and Font. If you don't dispose of those objects, you WILL eventully run the system out of resources. Like I said before, create object you're going to use over and over again once at the class level and dispose of them before your form closes.
|
|
|
|
|
your HTML tags aren't working, didn't you notice?
and multi-line code snippets deserve PRE tags, not CODE tags.
I'm not reading it the way it is now.
|
|
|
|
|
Ok, thanks a lot for all of your help, is working now, but now I want to know another thing that, is there anyway that I can copy this graphical text into clipboard and then paste into Richtextbox?
Thanks in advance.
|
|
|
|
|
mates,
I don't know where to put this question regarding crystal report but i work it in vb.net. Hopefully im in the correct forum. Anyway, if somebody could give me an idea or solution I highly appreciated.
Heres the problem:
How will i generate the crystal report to set the details regarding what the user input in form.
Example. In my form i have 2 textbox and a button.
If I input in textbox1 = 4 and textbox2 = 2. so the result is 4x2(4 by 2) in details of cr.
in report the data should 4 rows and 2 colums.
Sample data:
TG-5465444 TG-5465448
TG-5465445 TG-5465449
TG-5465446 TG-5465450
TG-5465447 TG-5465451
textbox1 = 3 and textbox2 = 1 ; 3 by 1
TG-5465444
TG-5465445
TG-5465446
i got this in access report, heres my code
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Page = 1 Then
If mintSkipped < mintToSkip Then
With Me
.MoveLayout = True
.NextRecord = False
.PrintSection = False
End With
mintSkipped = mintSkipped + 1
End If
End If
End Sub C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
Crystal Report is devided in 3 Section :
1 : Header
2 : Details
3 : Footer
If You have a repeated data (From Database) then insert the field in Details Section.
For More details you should need to learn Crystal Report.If you can think then I Can.
|
|
|
|
|
I need to open a YED.exe application when a user clicks on the .gml file in the tree view.
Now it is happening but in a separate window. I want this application to be launched in the form. Like what we have webbrowser to open many supported files.
Do we have anyother tools in VB6 so that i can launch the .exe within the Form?
Thanks,
Karthick.M
|
|
|
|
|
VB6 is no longer supported, and you would be well advised to get VB.Net. ------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
I dont have a option, I have to do it in VB6.
Please help if you knw how to.
Thanks,
Karthick.M
|
|
|
|
|
There is no native option to doing this in VB6 or VB.NET.
You have to use the Win32 function SetParent to tell the main window of the app that it's new parent is the window handle to your form other other hosting control. Google for "VB6 SetParent" for examples.
Be warned. Some applications have rendering problems when doing this and you user gets to move the application around just as if it was running on the desktop. They also get to close the app any time they want. You cannot prevent these things from happening.
|
|
|
|
|
hey
This is for outlook vba for loading a ref at outlook
Whit this you can load a reference in it whitout any manual input the only thing you need
= a refernce to let vbe work
so this is no solution if you only whant to load 1 reference
Application.VBE.ActiveVBProject.References.AddFromFile "C:\WINDOWS\system32\redemption.dll"
is there a other way at vba
or a way true c#.net or vb.net to load a ref en set active in outlook
thanks
|
|
|
|
|
There's no such thing as "setting a reference to active". And what you're doing is the only way to do it in VBA.
neverpleat wrote: or a way true c#.net or vb.net to load a ref en set active in outlook
I don't understand what you're asking. Are you asking if there is an equivilent method to doing this in C# or VB.NET?
|
|
|
|
|
Yes
if i can force this with c#.net from outside outlook
Thanks
|
|
|
|
|
Your answer isn't very complete.
You have an external application that wants to add a reference in a VBA project that's running in Outlook already?
C# has no direct equivilent. You'd have to do it the same way as you do it in the project, by calling the method on the VBE object you get in Outlook. Don't ask for examples - I don't have any. You'd have to Google for something.
|
|
|
|
|
hi
- i have outlook installed but not running
- i have written a application in c#
- i have some vba code that runs at outlook but need a reference
question 1
is there a way to let on the first run from my application to insert the reference in outlook ?
and just maby it can be done by the registry ?
Question 2
if question 1 yes
is there a way to let on the first run from my application to insert the vba code in outlook ?
-------------------------------------
i now how to check if it's the first run or not
google don't now , yet
thanksmodified on Thursday, March 4, 2010 10:21 AM
|
|
|
|
|
Why are you even setting the reference? Do you have some object that is changed out frequently that this reference is loading?
What is the reference to?
|
|
|
|
|
i realy need to have redemption.dll in the reference
and it's a easy way from doing this if i can program this ,then at next install of pc i don't need to remember that i need that reference to set on
and i'am sure it can be done the only way = how that's the question 
|
|
|
|
|
If all you're doing is trying to reinstall an Outlook VBA project if you reload your machine, the reference is saved with the project. You just need to put the project file back. Just search your user profile folder for "vbaproject.otm" and back the file up. When you reload your machine, put the file back where you found it.
|
|
|
|
|
can i force this with c#.net from outside outlook
|
|
|
|