|
-
Jan 25th, 2007, 04:06 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Gradient Button [2005]
How do I get this code to work from from the getgo? It works If I put it in the mouse events but not the controls paint event. I have tried adapting different methods from several threads but I cannot seem to get any of them to work.....
VB Code:
Private Sub DrawGradientButton(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint
Try
Dim g As Graphics = Button1.CreateGraphics
Dim rect As New Rectangle(0, 0, Button1.Width, Button1.Height)
Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.SlateGray, Drawing2D.LinearGradientMode.Horizontal)
Dim x As Single = CSng(Button1.Width / 2)
Dim y As Single = CSng(Button1.Height / 4)
Dim sBrush As New System.Drawing.SolidBrush(Color.WhiteSmoke)
Dim Font As System.Drawing.Font = Button1.Font
Dim txt As String = Button1.Text
g.FillRectangle(br, rect)
g.DrawString(txt, Font, sBrush, x, y)
br.Dispose()
g.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Thank you!!
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you. 
Please remember to mark threads as closed if your issue has been resolved.
Reserved Words in Access | Connection Strings
-
Jan 25th, 2007, 04:34 PM
#2
Hyperactive Member
Re: Gradient Button [2005]
Try changing the way you get the graphics object to:
VB Code:
Dim g as Graphics = e.Graphics
Oh and you'll need to delete the line..
Last edited by Tinbeard; Jan 25th, 2007 at 04:37 PM.
-
Jan 25th, 2007, 04:39 PM
#3
Thread Starter
Fanatic Member
Re: Gradient Button [2005]
It gives me this error:
VB Code:
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.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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 MyApp.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()
I am working on what and where, but i wanted to post that up here quickly.
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you. 
Please remember to mark threads as closed if your issue has been resolved.
Reserved Words in Access | Connection Strings
-
Jan 25th, 2007, 04:40 PM
#4
Hyperactive Member
Re: Gradient Button [2005]
see the edi to my post above:
delete the g.dispose() line
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|