Hi all
i just wanna ask if any one can give me the related function with colordialog(vb.net) and if i can change backcolor of form with it?how?

Thanks:confused:

Dani AI

Generated

A quick, practical follow-up that ties together the answers already posted by and and addresses the follow-ups from and .

ColorDialog is a non-visual Windows Forms component (System.Windows.Forms.ColorDialog). It can be dropped from the toolbox or created at runtime. If an identifier like ColorDialog1 is underlined in the editor, that usually means the component was not added to the form or it was renamed — declaring a local instance in code avoids that problem.

Controls expose text and background colors through different properties. Most controls use ForeColor for text and BackColor for background; a RichTextBox uses SelectionColor for the color of selected text. The snippets below show two safe, runtime approaches that are different from the designer-only examples already in the thread.

' change ForeColor of the currently focused control (if writable)
Dim dlg As New ColorDialog()
dlg.FullOpen = True
If dlg.ShowDialog(Me) = DialogResult.OK Then
    Dim ctrl As Control = Me.ActiveControl
    If ctrl IsNot Nothing Then
        Dim prop = ctrl.GetType().GetProperty("ForeColor")
        If prop IsNot Nothing AndAlso prop.GetSetMethod() IsNot Nothing Then
            prop.SetValue(ctrl, dlg.Color, Nothing)
        End If
    End If
End If
' apply chosen color to a RichTextBox selection or to all text if nothing selected
Dim dlg2 As New ColorDialog()
dlg2.AllowFullOpen = True
If dlg2.ShowDialog() = DialogResult.OK Then
    If RichTextBox1.SelectionLength > 0 Then
        RichTextBox1.SelectionColor = dlg2.Color
    Else
        RichTextBox1.ForeColor = dlg2.Color
    End If
End If

Notes and cautions: TextColor is not a VB.NET control property — use ForeColor. Some controls (standard Buttons under Windows themes) may ignore ForeColor unless owner-drawn or FlatStyle is adjusted. To persist a color between runs, store Color.ToArgb() (an integer) in settings and recreate the Color with Color.FromArgb(...) on startup.

Recommended Answers

All 8 Replies

Add ColorDialog control to the form , then change its property to the way you want it to show .

to show the dailog

ColorDialog1.ShowDialog()

you can get the color that user selected by ColorDialog1.Color after this you can set the backcolor of form to this color

Hi all
i just wanna ask if any one can give me the related function with colordialog(vb.net) and if i can change backcolor of form with it?how?

add a button and a colordialog to the form and type in the following code in the button_click event

If Me.ColorDialog1.ShowDialog = DialogResult.OK Then
            Me.BackColor = ColorDialog1.Color
        End If

Thanks , its worked ;)

the function or code

Me.ColorDialog1.ShowDialog() to change the back and fore color with control, i get every thing except this. Why is my
code window highlighting colordiaog1 when i type....should i declare something can some give me the whole code to change the fore color and the back color of a button during run time with control using this code?
what is colordialog1 by the way? Is it an object? what is it?
is it to do with visual basic i use? mine is microsoft visual basic 2008 express edition. Also guys please tell me if there is any website where i can get tutored visual basic....please
Thank you x_x

Hi all
i just wanna ask if any one can give me the related function with colordialog(vb.net) and if i can change backcolor of form with it?how?

add a button and a colordialog to the form and type in the following code in the button_click event

If Me.ColorDialog1.ShowDialog = DialogResult.OK Then
            Me.BackColor = ColorDialog1.Color
        End If

I just wanted to ask, the above code would change the back ground color of the screen, however, I am writing a text editor and thought it would be cool to write up some code so that the user can change the text color like you can in ms word and such, so please tell me if I am wrong but if I changed the second line of the above code to
Me.TextColor = ColorDialog1.Color.
Would that work?

Thanks

John

Hi

Also guys please tell me if there is any website where i can get tutored visual basic....please

You can find some tutorials for VB 2008, here.

never mind all sorted.

Hi discovery_power.

You cannot hijack another thread to ask your question but you have to start your own thread instead. Please do not resurrect old threads. Have a look at forum rules.
Please read before posting - http://www.daniweb.com/forums/thread78223.html

Thread Locked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.