In visual basic how will we change the backcolor of the form randomly when we click the command button?
In this program we want to change the background color of the form by command button when we click on this it will change the bakground color.
everytime when we'll run the program it chose the different color.
a 6ya Technician can help you resolve that issue over the phone in a minute or two.
Best thing about this new service is that you are never placed on hold and get to talk to real repair professionals here in the US. click here to Talk to a Technician (only for users in the US for now) and get all the help you need. Goodluck!
- If you need clarification, ask it in the comment box above.
- Better answers use proper spelling and grammar.
- Provide details, support with references or personal experience.
Tell us some more! Your answer needs to include more details to help people.You can't post answers that contain an email address.Please enter a valid email address.The email address entered is already associated to an account.Login to postPlease use English characters only.
Tip: The max point reward for answering a question is 15.
You will probably want to be able to update some value of some field when doing database programming. This is done with Edit and Update. We will try to change the value of the "Phone" field by editing the text in the text box
and clicking a button.
Put a command button on the form and name it "cmdUpdate". Then copy the following code to the project.
Private Sub cmdUpdate_Click()
Could it be that simple? Yes. This changes the phone number of our
selected person. Or to put it technically: This changes the value of the
"Phone" field of our current record. Imagine the current record being a
set of boxes, with a field in each box. T
he Edit method takes the lid off all of the boxes and Update puts them back on. When we write rsMyRS!Phone = txtPhone.Text we replace the content of the "Phone" box with the content in the text box.
How to Run a Visual Basic Program on a PC
By an eHow Contributor
Like C++, C Sharp and Java, Visual Basic (VB) is
an object oriented programming language. Recently it was integrated to
the Microsoft .NET Framework. The .NET Framework is a software
infrastructure that speeds up program development. It is supported by
the Microsoft Visual Studio Integrated Development Environment (IDE), Microsoft's chief programming environment, and that of SharpDevelop. Difficulty: Easy
Things You'll Need:
Visual Microsoft Studio and .NET Framework
Launch your Microsoft Visual Studio. It is a "heavy" application so depending on how much RAM you have it may take a few minutes to load.
Click the Project tab on the first screen. Notice two buttons
at the bottom of the screen named "New Project" and "Open Project."
Since the tutorial assumes that this is your first VB program, click the
"New Project" button. If you worked on a project before, its name will
appear in an area labeled "Open an Existing Project" with a hyperlink
that opens the project.
Select "Windows Application" in the "Visual Basic Projects" folder if you intend to run your end program on a computer running a Microsoft Windows operating system.
Focus in the "Name" text box near the bottom. Change the name from the
default to something more descriptive such as "MyFirstVBProgram." Leave
the Location to the default value to save your project to the "My
Documents" folder. Press OK.
Concentrate on the grey square area with the arrays of dots.
This is the "form." The pinboard shows where components like buttons and
text boxes will be installed to make a complete graphic user interface
(GUI). The purpose of the grid is to align the components.
Run your program. Click "Debug" from the menu bar. Click
"Start" from the drop down menu. Alternatively, you can press F5 on your
Enjoy your first Visual Basic program in its simplest form.
It is identical to the form in Step 4 except that the dots are gone.
What you are looking at is a stand alone program that exists as an
".exe" file having the same name as your project. You can find it under
the MyFirstVBProgram folder by default.
Understand the difference between the two distinct
environments of the IDE, the Design Environment and the Debug
Environment. You saw the Design Environment in Step 4 of this tutorial.
That was the environment where you could design a GUI on the form using
your mouse. The Debug Environment takes over during the compilation
interval in Step 5. That is where you can insert break points in your
source code so that you test the correctness of the program.
Open Visual Basic and select "Standard Exe" to create a new project.
Add a button by clicking the square button tool on the right, and then clicking and dragging in the main window.
Click the button once to open the "Properties" window on the right. Select the "(Name)" property, and type "myCmdButton" as the name.
Double-click the button to open up the code-view window. Type the following in the white space under "Private Sub myCmdButton_Click()": myCmdButton.enabled = False;
Click the blue "Run" button on the top toolbar of Visual Basic. Because you set enabled to "false" in the previous step, you will see your button grayed out, and nothing will happen when you click it.
You can create a macro by using the macro recorder to record a sequence of actions, or you can create a macro from scratch by entering Visual Basic for Applications code in the Visual Basic Editor. Open a new document. From the Tools menu, choose Customize. Click the Commands tab and then scroll down in the Categories box and select Macros. You’ll see the names of any macros you've created in the Commands box on the right-hand side. Click, hold, and drag your macro onto any toolbar and release, as shown in Figure D. A button with the name of the macro will appear on the toolbar.
Use the "Style" property DataGridView1.Item(ColumnIndex, RowIndex).Style.BackColor = Color DataGridView1.Item(ColumnIndex, RowIndex).Style.ForeColor = Color or DataGridView1.CurrentCell.Style.BackColor = Color DataGridView1.CurrentCell.Style.ForeColor = Color
here is the solution;
solution 1 (need 3 text boxes, Namely text1, text2 & text3 & a command button. Put the code below in the button click event)
Dim x, y As Integer
x = Text1
y = Text2
Text3 = x ^ y
solution 2 (put the code either in form load event or button click event)
Dim X, Y As Integer
X = InputBox("Enter X", "X ? ")
Y = InputBox("Enter Y", "Y ? ")
MsgBox "X^Y = " & X ^ Y
ok you have 3 choices
assuming your form name is main.
main.backcolor = color.blue
this.backcolor = color.blue
me.backcolor = color.blue
you can type your form name followed by the . to get all options for changing it peoperties,
or you can type this. refering to the form your are currently in, this has the effect just as the form name,
If you are programming on the formitself you can use
me. same effect as the form name..