Hi
it's me again
with the silly problems in my vb .net codes :(
I have a serious problem with combo box
i need to use the selected item in combo box
when user selects for example GREEN from be drop down list after than i need to put that green into the rest of my code, i need to draw a line in green
but i dont know how to tell the program to use Green
i tried setting up a variable for that, like : Dim rang as string = cmbcolor.selecteditem
but it doesn't work
can you please help me?
thank you

Recommended Answers

All 8 Replies

what do you want it's not clear and i can't understand pleas write clear what u want after selecting of green color.
so i can help You.

oh ok
look
there's a combo box
with items like white , black , red, blue
when the program runs user must select a color in combo box
then the program must draw a rectangle with the color and the coordinates that the user have already entered
gr.DrawRectangle(Pens.*****, X, Y, Width, Height)

instead of the stars must be the color that the user selected in the combo box
i don't know how to transfer the date from combo box to rest of the code :(
was it clear this time? :(
i'm sorry bcuz my native language is not english maybe i cannot tell exactly what i want

Hi
it's me again
with the silly problems in my vb .net codes :(
I have a serious problem with combo box
i need to use the selected item in combo box
when user selects for example GREEN from be drop down list after than i need to put that green into the rest of my code, i need to draw a line in green
but i dont know how to tell the program to use Green
i tried setting up a variable for that, like : Dim rang as string = cmbcolor.selecteditem
but it doesn't work
can you please help me?
thank you

to get selected text use the variable
dim rang as string = cmbcolor.getitemtext.selecteditem()

here one example i am written here i think this will help you.

Imports System.Drawing
Imports System.Drawing.Drawing2D

Private sub form1_paint(byval sender as object, byval e as System.Windows.Forms.PaintEventArgs)
dim g as graphics
g=form1.CreateGraphics()
dim mybrush as solidBrush
mybrush=Brushes.Red
g.Fill.Rectangle(mybrush,10,10,200,100)
mybrush.dispose()
end sub

and another code for you

Imports System.Drawing
Imports System.Drawing.Drawing2D

Private sub form1_paint(byval sender as object, byval e as System.Windows.Forms.PaintEventArgs)
dim g as graphics
g=form1.CreateGraphics()
dim b as SolidBrush=System.Brushes.ActiveBorder
g.Fill.Rectangle(b,10,10,200,100)
b.dispose()
g.dispose()
end sub

i think this example help you.
if it's work mark thread as solve.

u know all my problem is that when i have a variable for color like this :
dim rang as string = cmbcolor.getitemtext.selecteditem()

then i cannot put this rang in this :
gr.DrawLine(Pens.rang, X1, Y1, X2, Y2)

it does not accept variable so i have to repeat so many lines bcuz i have to use If

u know all my problem is that when i have a variable for color like this :
dim rang as string = cmbcolor.getitemtext.selecteditem()

then i cannot put this rang in this :
gr.DrawLine(Pens.rang, X1, Y1, X2, Y2)

it does not accept variable so i have to repeat so many lines bcuz i have to use If

You can use the Color.FromName Method to accomplish that

Here is an example

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim range As String = Me.ComboBox1.GetItemText(Me.ComboBox1.SelectedItem)
        Dim gfx As Graphics = Me.CreateGraphics
        Dim pen As New System.Drawing.Pen(Color.FromName(range))
        gfx.DrawLine(pen, 100, 100, 200, 200)

    End Sub

thank u

Very Thank you..

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.