Saving color in Mysettingscolor and returning - vb.net

I am coding on vb.net. I have a program that the user select a color from a picture and the color is stored to compare with another pixel from the picture, then when the colors match it make a mark in the picture. Then I save the color in my.settings.myColor. When the user select the color, it returns as "Color[A=255, R=255, G=255, B=255]", until here works totally fine. The problem is, when I close the program and reopen, it does not return like "Color[A=255, R=255, G=255, B=255]", it returns like this Color[White]. So, when I do to compare the colors to find some matching colors, it does not find anything. I am assuming it is because, it is returning different, am I right?
Dim cor As Color = My.Settings.Mycolor
Private Sub FrmBitmaps_Load(sender As Object, e As EventArgs) Handles MyBase.Load
colour = My.Settings.Mycolor
cmdColorPicker.BackColor = My.Settings.Mycolor
End Sub
Thanks

I created a setting in the application properties on the settings tab. It looks like this.
To get the Type scroll down to Browse in the drop down and find System.Drawing.Color. The scope is set to User so it can be edited.
To set the setting
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Settings.TestColor = Color.FromArgb(255, 237, 28, 36)
End Sub
Then I closed the application and re-openned it and clicked Button 2.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim MyRetrievedColor = My.Settings.TestColor
TextBox1.BackColor = MyRetrievedColor
End Sub

Related

vb.net textbox not displaying text or colors

I have many applications that reliably display data and colors in text boxes. I copied one working program to make a new application. There are about 10 text boxes that I use for data displays. Some are working - and some are not. Here are 2 samples - the Switch code works in many programs - but here it will put the word "ON" in the box but no color, and then when the switch is off - no change to the textbox. The code seems not to care between the .AppendText or the .text = variable control. I have tried changing the properties of the text box to public but no luck. I have tried adding the .show object, and verified the .visible attribute in the properties view. A similar problem is with the DistanceUnitsOut and the NextImageDistanceOut - I can step through the code and see the values, but the displayed data does not change! I have tried changing the definition of the display to public - no joy!
SwitchStatusBox.clear
SwitchStatusBox.AppendText(SwitchStatusIn)
If SwitchStatusIn = "OFF" Then
SwitchStatusBox.BackColor.Equals(Color.Red)
SwitchStatusBox.Show()
Switch_Is_On = False
Else
SwitchStatusBox.BackColor = Color.Green
SwitchStatusBox.Show()
Switch_Is_On = True
End If
If dDistance > 1.0 Then
'show distance in Miles
DistanceUnitsOut.Clear()
DistanceUnitsOut.Text = "MI"
NextImageDistanceOut.Clear()
NextImageDistanceOut.Text = CType(dDistance, String)
Else
NextImageDistanceOut.Clear()
NextImageDistanceOut.Text = CType(dDistanceFT, String)
DistanceUnitsOut.Clear()
DistanceUnitsOut.Text = "FT"
End If
Private Sub NextImageDistanceOut_TextChanged(sender As Object, e As EventArgs) Handles
NextImageDistanceOut.TextChanged
End Sub
Private Sub DistanceUnitsOut_TextChanged(sender As Object, e As EventArgs) Handles
DistanceUnitsOut.TextChanged
End Sub
To see how the .Equals function works...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a = TextBox1.BackColor.Equals(Color.Red)
Debug.Print(a.ToString)
End Sub
In my test app this prints False in the Immediate window.
The answer is that some time ago I began using <variablename_OUT> followed by the TEXT = as in :
NextImageDistanceOut.Text = CType(dDistanceFT, String)
what worked was:
NextImageDistanceOut.Appendtext(CStr(dDistanceFT))
I still don't understand why the first did not work - Both require a previous
NextImageDistanceOut.Clear

How can I write data into a row in Virtual Studio? (MS Access Database file"

I would like to make a small application what can make easier my work.
I have to make one ordering process some labels where I have a plan and from the plan I have to one excel list making with the labelnames what will be printed by the Manufacturer. We have a lot of type of the label (names) but they are fixing. (160 pieces differentnames).
So I make this always if I get a new plan then I make new label-list. I do it alway by hand cell by cell.. Sometime I have to filling out 400 cell for one plan... I don’t have a lot’s of time to this..
So I started making my first Windows app with Visual Studio(in Windows From – Visual Basic).
I found some cool video, so I already have the „basics”.
I connected one MS Access database to my Project where I would like to store the datas.
And now i have trouble.. I have some Comboboxes. I would like to choose some cases and then I would like to update the database where the rows will be filled with the correct values. If its done, i can this exporting to excel and sendig forward to the Manufacturer.
I have a textbox where I write the Plan name (it linked to the database first Column)
And then:
So the Combobox1 have Sektor A, B, C, D ,E, F (six value)
The Combobox2 have 09RRU, 09RSU, 18RRU ... empty - (eight value)
The Combobox3 have 21RRU, 21RSU, 26RRU ... empty - (eight value)
The Combobox4 have ja or nein (only two value)
and so on.. I have 8 Combobox.
My Idea:
If I select the Sektor A and 09RRU , the another two is empty and nein, then I click on the Update button I would like to get back in database 09.SekA1, 09.SekA2, AISG.SekA
If I select the Sektor A and 09RRU and 21RRU and ja, then after click Update, I would like get 09.SekA1, 09.SekA2, 21.SekA1, 21.SekA2, 09.21.SekA1, 09.21SekA2, AISG.09.21.SekA
….
I can every type of labels line by line writing if needed, I think I have to do this. I don’t think so can I dynamic Arrays making which can the different String e.g. ( Text (09) & Text (.SekA) & Text(1)) creating. I just now started the VB..
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox8.SelectedIndexChanged
SektorForm1()
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
End Sub
Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
End Sub
Private Sub SektorForm1()
BEschriftungenDataSet.Standort.RRU18Column = "18.SekA1"
BEschriftungenDataSet.Standort.RRU21Column = "18.SekA2"
BEschriftungenDataSet.Standort.RRU26Column = "AISG.18.SekA"
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.StandortTableAdapter.Fill(Me.BEschriftungenDataSet.Standort)
ComboBox1.SelectedIndex = 5
ComboBox2.SelectedIndex = 3
ComboBox3.SelectedIndex = 3
ComboBox4.SelectedIndex = 1
ComboBox5.SelectedIndex = 1
ComboBox6.SelectedIndex = 1
ComboBox7.SelectedIndex = 1
ComboBox8.SelectedIndex = 0
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
On Error GoTo SaveErr
StandortBindingSource.EndEdit()
StandortTableAdapter.Update(BEschriftungenDataSet.Standort)
MessageBox.Show("Saved")
End Sub
Could some one for me Helping what is wrong in my code? I tried some data inserting to tha database when I choose someting in Combobox1 but it doesn't work..
I get failures: BC30526 Property'RRU18Column' is 'ReadOnly' and BC30311 Value 'String' cannot be converted to 'DataColumn'..
And giving some help how I sould staring building up my cases to my Combobox chooses..
Thanks guys

Improve UI responsiveness on windows form application

I am currently working on a project and decided to create a user interface for it using visual studio with a windows forms application(Visual Basic).
The problem I'm facing is that the user interface doesn't respond as quickly and smoothly as I'd like it to.
Mainly, I am using pictures as buttons to make the user form look more modern.
However, when I hover my mouse over a "button" it takes a while until the "highlighted button" appears.
P1 is the picture of the "normal button" and P2 is the picture of the "highlighted button".
Here is the short code I have for now:
Public Class Main
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub PictureBox1_MouseHover(sender As Object, e As EventArgs) Handles P1.MouseHover
P1.Visible = False
P2.Visible = True
End Sub
Private Sub P2_MouseClick(sender As Object, e As MouseEventArgs) Handles P2.MouseClick
'Call cmdInit()
'Call cmdConnectRobot()
'Call cmdUnlock()
End Sub
Private Sub Main_MouseHover(sender As Object, e As EventArgs) Handles Me.MouseHover
If P2.Visible = True Then
P2.Visible = False
P1.Visible = True
End If
End Sub
Private Sub P4_Click(sender As Object, e As EventArgs) Handles P4.Click
End Sub
End Class
Another problem I'm facing is that when I call other subs, the user form becomes unresponsive while the sub is running.
I researched and found that I could implement multi threading or async tasks but I'm a bit lost and would be extremely grateful if someone could guide me or point me in the right direction.
Thanks in advance!!
In this case your UI is responsive, however the MouseHover event is only raised once the mouse cursor has hovered over the control for a certain amount of time (default is 400 ms), which is what is causing the delay.
What you are looking for is the MouseEnter event, which is raised as soon as the cursor enters ("touches") the control:
Private Sub P1_MouseEnter(sender As Object, e As EventArgs) Handles P1.MouseEnter
P1.Visible = False
P2.Visible = True
End Sub
You can then use that together with the MouseLeave event on the second picture box to switch back to the non-highlighted image:
Private Sub P2_MouseLeave(sender As Object, e As EventArgs) Handles P2.MouseLeave
P1.Visible = True
P2.Visible = False
End Sub
However switching picture boxes like this is not optimal. I recommend you to look into how you can use Application Resources, then modify your code to only switch the image that one picture box displays.
Here are the basic steps:
Right-click your project in the Solution Explorer and press Properties.
Select the Resources tab.
To add an image either:
a. Drag and drop the image onto the resource pane.
b. Click the arrow next to the Add Resource... button and press Add Existing File....
Now, in your code add this right below Public Class Form1:
Dim ButtonNormal As Image = My.Resources.<first image name>
Dim ButtonHighlighted As Image = My.Resources.<second image name>
Replace <first image name> and <second image name> with the names of your button images.
Now you only need one picture box for the button:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
P1.Image = ButtonNormal
End Sub
Private Sub P1_MouseEnter(sender As System.Object, e As System.EventArgs) Handles P1.MouseEnter
P1.Image = ButtonHighlighted
End Sub
Private Sub P1_MouseLeave(sender As System.Object, e As System.EventArgs) Handles P1.MouseLeave
P1.Image = ButtonNormal
End Sub
I'll start by saying i'm not a programmer by trade, and i'm sure someone will point out better ways of doing these things, but in regards to the threading question it's fairly simple to implement.
Imports System.Threading
Public Class Form1
Dim WorkerThread As New Thread(AddressOf DoWork)
'WorkerThread' can be any name you like, and 'DoWork' is the name of the sub you want to run in the new thread, and is launched by calling:
WorkerThread.start()
However there is a catch, the new thread is not able to interact directly with the GUI, so you cannot change textbox text etc... I find the easiest way to get changes made to the GUI is to drag a timer onto your form, and have the new thread change variables (pre-defined just below Public Class Form1), then use the Timer1 Tick event to monitor the variables and update the GUI if there are any changes.

scroll bar visual basic properties

I work on project with scroll bars. Each scroll bar holds a max value of 255 (the color codes) 1 scroll bar is red, second green third blue. When I change the large value property from 1 to 5 (it is required in the project) and slide the scroll bar all the way to the end the final value is 251 instead of 255 and it must be 255. Small change is set to 1. I am currently learning vb, does anyone know how to solve this issue?
Here is the code I have and we are not allowed to use variables yet
The explicit option must be on as well as the strict.
Option Explicit On
Option Strict On
Public Class frmMixer
Private Sub cmdExit_Click(sender As Object, e As EventArgs) Handles cmdExit.Click
Application.Exit()
End Sub
Private Sub hsbRed_ValueChanged(sender As Object, e As EventArgs) Handles hsbRed.ValueChanged
lblRed.Text = Convert.ToString(hsbRed.Value)
picColor.BackColor = Color.FromArgb(hsbRed.Value, hsbGreen.Value, hsbBlue.Value)
End Sub
Private Sub hsbGreen_ValueChanged(sender As Object, e As EventArgs) Handles hsbGreen.ValueChanged
lblGreen.Text = Convert.ToString(hsbGreen.Value)
picColor.BackColor = Color.FromArgb(hsbGreen.Value, hsbGreen.Value, hsbBlue.Value)
End Sub
Private Sub hsbBlue_ValueChanged(sender As Object, e As EventArgs) Handles hsbBlue.ValueChanged
lblBlue.Text = Convert.ToString(hsbBlue.Value)
picColor.BackColor = Color.FromArgb(hsbRed.Value, hsbGreen.Value, hsbBlue.Value)
End Sub
End Class
Change large change property for the scroll bar to 1 (my project started at 10 and changing it to 1 solved it)
Click the scrollbar -> properties window should show
Scroll down to "LargeChange" property and change to 1

combox selected index didnt work on picturebox

Now what i was doing is when i click a button group box 1 and group box 2 will show out i want to select the combobox item than the picturebox item will load
and this can be used it multiple time like when button-5 clicked the combobox item name will change and the picture will change too.
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
GroupBox1.Show()
GroupBox2.Show()
comboboxselectdiffrent.Items.Add("pizza_ChickenSupreme")
comboboxselectdiffrent.Items.Add("pizza_CockadoodleBacon")
If comboboxselectdiffrent.SelectedIndex = 0 Then
PictureBox1.Image = PIZZA_HUT_SYSTEM_NEW_VER.My.Resources.Resources.pizza_ChickenSupreme
ElseIf comboboxselectdiffrent.SelectedIndex = 1 Then
PictureBox1.Image = PIZZA_HUT_SYSTEM_NEW_VER.My.Resources.Resources.pizza_CockadoodleBacon
End If
End Sub
Can anyone tell me what i was do wrong? i have no idea why it wont work
After looking at your code personality I would have the event trigger from the combobox click, that way it will save the user having to first click on the combo to select their pizza and then having to click on a button to load the picture & details. Nevertheless try this.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("pizza_ChickenSupreme")
ComboBox1.Items.Add("pizza_CockadoodleBacon")
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
GroupBox1.Show()
GroupBox2.Show()
Select Case ComboBox1.SelectedItem
Case Is = "pizza_ChickenSupreme"
PictureBox1.ImageLocation = "Pictures/mypic.jpg"
Case Is = "pizza_CockadoodleBacon"
PictureBox1.ImageLocation = "Pictures/mypic1.jpg"
End Select
End Sub
End Class
Using a custom Folder within the solution explorer will be better than using a setting resource. Create a folder and drag your pictures into it and change the name of the image location to suit your needs.
Also i think using the items name is better than the items index because what happens if someone reason that indexed item is to change from 1 to 5, you would have to recode it all, but by using the items name, it has more detail as to what to look for.
If you have any problems, leave a comment and I will do my best to help you out.Happy Coding!