|
Can a radio button have more than 1 function?
At the top of my form is a textbox that the user will enter their name.
When a radio button is selected, a corresponding picture will show up.
I also need a message to show up below at will display a message: It will be [choice of: sunny, snowy, rainy, cloudy - depending on which radio button is selected] weather today, [name entered].
I was thinking that I could do separate text boxes for the [sunny, snowy, cloudy, rainy] and the [name box], but how do I make them transfer their text to the corresponding text boxes?
Public Class Form1
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
If Me.RadioButton1.Checked = True Then
Me.PictureBox1.Visible = True And
Me.PictureBox2.Visible = False
Me.PictureBox3.Visible = False
Me.PictureBox4.Visible = False
End If
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
If Me.RadioButton2.Checked = True Then
Me.PictureBox2.Visible = True
Me.PictureBox1.Visible = False
Me.PictureBox3.Visible = False
Me.PictureBox4.Visible = False
End If
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
If Me.RadioButton3.Checked = True Then
Me.PictureBox3.Visible = True
Me.PictureBox1.Visible = False
Me.PictureBox2.Visible = False
Me.PictureBox4.Visible = False
End If
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
If Me.RadioButton4.Checked = True Then
Me.PictureBox4.Visible = True
Me.PictureBox1.Visible = False
Me.PictureBox2.Visible = False
Me.PictureBox3.Visible = False
End If
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles ButtonExit.Click
Close()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles SSRC.TextChanged
End Sub
End Class
|
|
|
|
|
Sorry... Wrong approach!
Why?
Imagine... when you change the state of RadioButton control, corresponding control (PictureBox ) is changing its visibility:
Me.PictureBoxIndex.Visible = Me.RadioButtonIndex.Checked
What i'm trying to tell you is that: you can refer to the control in Windows.Forms.ControlsCollection[^] via its Index or Name . So, to be able to play with four PictureBoxes, you have to write method which accepts number as input parameter:
Sub ChangePictureBoxVisibility(index As Integer)
Me.Controls("PictureBox" & index.ToString()).Visible = Me.Controls("RadioButton" & index.ToString()).Checked
End Sub
Usage:
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
ChangePictureBoxVisibility(4)
End Sub
Got the idea?
For further information, please see: Visual Basic Fundamentals: Development for Absolute Beginners[^]
|
|
|
|
|
Thank you for your help. I think I got that part, but do you know how to have the contents of Label2 move to another Label3 when a radio button is clicked?
Does it have to do with writing a code to make the labels equal one another?
Thank you.
|
|
|
|
|
Use the same logic:
Me.LabelIndex.Text = Me.LabelAnotherIndex.Text
|
|
|
|
|
Hello..,
I'm stump. I can't get to navigate correctly in my listview.
My objective is to list the files and folders in the listview and when I click on the folder it will show the files. However, if i click on the folders that also contains folders (and files) and when I click on the folder it wont work. (sorry if its not clear..)
here's what I have accomplished so far.
Dim FPath As String
Dim s1 As String = lblSource.Text
If lvFiles.SelectedItems.Count > 0 Then
FPath = s1 + "\" + lvFiles.SelectedItems(0).SubItems(0).Text
If Directory.Exists(FPath) Then
ShowFiles(FPath)
Else
MsgBox("not valid")
End If
End If
Please help.. I can't save the correct path then append the next folder name
.. Editing this post.. As I tried saving the path to a txtPath.txt and created a back button
Dim str As String
str = lblFolder.Text & "\.."
lblFolder.Text = str
ShowFiles(str)
I tried and it works.. unfortunately my txtPath.txt is messed up.. I get something like:
C:\000 Test\Conv\Sampple\..\Sample2\..
Again.. Please Help.
modified 17-Sep-15 6:57am.
|
|
|
|
|
This control should help[^].
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Thank you for the link. Though, it indeed helps me with my projct easily. I want to try programming how it works and understand it.
|
|
|
|
|
You probably need to use a recursive process. As you look at each item in the list you do the following:
- If it is a directory, then you need to get its contents into a new list, then pass the directory and new list back into the same subroutine.
- If it is a normal file do whatever processing for a file.
- If there are no more items in the list then return from the subroutine.
|
|
|
|
|
I'm so sorry.. I don't really get it.
|
|
|
|
|
Sorry, it is a bit of an odd concept if you have not done it before. I don't do VB so will have to use pseudo code:
Function ListDirectory: Param rootPath, Param ListOfFiles
ForEach file in ListOfFiles ' loop through all files in the list
If file == typeof.Directory Then
Path newPath = rootPath+"\"+file ' get the full path of this directory
List newList = new List(newPath.Files) ' get a list of the files (and folders) in the directory we just found
ListDirectory(newPath, newList) ' and process this new directory by recursively calling the ListDirectory function
Else
Display(file) ' if it's a normal file do whatever
EndIf
EndFor
EndFunction
This is essentially how a TreeView is built. As the code traverses the directories it will process each one it finds. As it gets to the end of each directory it returns from the function and eventually gets to the point where there are no more files in the list.
|
|
|
|
|
Thank you for this and sorry for the late reply.. I decided to rest my mind yesterday.
I'll do my best to transform this to vb.net. Hope it goes well
(btw, I'm not that good in programming still in the basics i guess)
Regards,
|
|
|
|
|
I need to create a tool that will recursively take ownership of a folder for our helpdesk team, we logon with admin tokens to perform administrative tasks so anyone who uses this tool will only be IT personnel and will have local admin rights when they logon with their token. Users are losing data because of corrupt file synchronization. The only way we can retrieve it is to take ownership of the c:\windows\csc and its contents. This is a very short explanation of why I need a tool, the story is much longer but this lays out why I started this project. I am new to visual basic and programming.
I wrote a program that will allow you to browse to the folder you want to take ownership of but I can't figure how get all the subdirectories. Can someone please help me make this program work recursively?
Here is the main part of the code and this will take ownership on the parent directory eg. c:\test:
#End Region
Private Sub bnBrowseFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnBrowseFolder.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
Me.folderName.Text = FolderBrowserDialog1.SelectedPath
End If
End Sub
Private Sub bnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnQuit.Click
Me.Close()
End Sub
Private Sub bnDoit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnDoit.Click
If tbUserName.Text = "" Then
MsgBox("Please type your NMEA account name (eg. Domain\adminaccountname)", MsgBoxStyle.Exclamation)
Exit Sub
End If
strPath = folderName.Text
For Each Folder In IO.Directory.GetDirectories(strPath, "*", IO.SearchOption.AllDirectories)
Next
strPath = folderName.Text
strUser = tbUserName.Text
Try
ChangeOwner(strPath, strUser)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical)
End Try
MsgBox("Done!")
End Sub
|
|
|
|
|
You would need to create the method in a recursive way but before going to that, wouldn't it be easier to execute takeown using a new process?
In other words something like
Process.Start("takeown /F directoryname /R /A")
For more info, see takeown[^]
|
|
|
|
|
It would be easier but I want to do it this first. Once I get this working I may do two more projects one with Takeown and one using WMI Win32_Directory TakeOwnershipEx Then test all 3 and see which one I like better. Takeown and WMI have been suggested to me but I really want to make this work first.
I have used takeown a lot as well as icacls from the command line.
How would I create the method in a recursive way? I have tried numerous way I have found numerous ways searching the internet but I can't do anything the right way. I even used the WMI Code Creator with elevated privileges and it fails even though I can take ownership of the parent directory with my tool. I am new to programming and I am learning but I need help.
|
|
|
|
|
If you want to create a recursive function you need to loop through the directories and for each directory call the same function again.
Consider the following code:
Sub HandleDir(directory As String)
Try
System.Diagnostics.Debug.WriteLine("I'm in directory " & directory)
For Each subdir As String In System.IO.Directory.GetDirectories(directory)
HandleDir(subdir)
Next subdir
Catch exception As System.Exception
System.Diagnostics.Debug.WriteLine(exception.Message)
End Try
End Sub
You can try that by calling it for example like this
HandleDir("C:\")
That should list all the directories where you have access.
|
|
|
|
|
once I add this how do I connect that with the part of the code that executes the change owner?
Try
ChangeOwner(strPath, strUser)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical)
End Try
Would I change this to?
Subdir = Me.FolderName.Text
Try
System.Diagnostics.Debug.WriteLine("I'm in directory " & directory)
For Each subdir As String In System.IO.Directory.GetDirectories(directory)
ChangeOwner(subdir, strUser)
Next subdir
Catch exception As System.Exception
System.Diagnostics.Debug.WriteLine(exception.Message)
End Try
strpath comes from here:
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
Me.folderName.Text = FolderBrowserDialog1.SelectedPath
End If
I really appreciate your help by the way.
|
|
|
|
|
Just put the code to change the ownership of a single directory in place of the debug.writeline. Or if you need to set the ownership before entering the directory, then inside the loop. Just remember to pas the user as a parameter
For example
Sub HandleDir(directory As String, userName as String)
Try
ChangeOwner(directory, userName)
For Each subdir As String In System.IO.Directory.GetDirectories(directory)
HandleDir(subdir, userName)
Next subdir
Catch exception As System.Exception
System.Diagnostics.Debug.WriteLine(exception.Message)
End Try
End Sub
And to call
HandleDir(Me.folderName.Text, strUser)
|
|
|
|
|
Mika thank you so much for helping with this tool. Your suggestion was the difference. I was able to take ownership of only the parent directory at first. So I decided to try and implement recursive permissions first. I got that to work right away. So I put that piece of code at the of the same sub routine that I called the change of ownership and it worked on the first try after permissions were applied. I had ownership of every sub-directory and full control permissions. I have a few more tasks to implement but this was the major obstacle. Once again thank you very much.
Here is the code for the whole thing. Some of it is generated by visual studio express. I also used several examples I found on the internet and molded them into what I needed.
'CSC TAKE OWNERSHIP AND DATA RECOVERY TOOL
'This tools will recursively take ownership of the c:\windows\csc folder. Then copy the affected users
'folder and backup their user profile to a network share then remove all the folders under c:\windows\csc\v2.06\namespace and delete all user profiles.
Imports System.IO
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Security.AccessControl
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents FolderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog
Friend WithEvents folderName As System.Windows.Forms.TextBox
Friend WithEvents tbUserName As System.Windows.Forms.TextBox
Friend WithEvents bnBrowseFolder As System.Windows.Forms.Button
Friend WithEvents bnDoit As System.Windows.Forms.Button
Friend WithEvents bnQuit As System.Windows.Forms.Button
Friend WithEvents Label2 As Label
Friend WithEvents PictureBox1 As PictureBox
Friend WithEvents Label3 As Label
Friend WithEvents LinkLabel1 As LinkLabel
Friend WithEvents Label4 As System.Windows.Forms.Label
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
Me.folderName = New System.Windows.Forms.TextBox()
Me.tbUserName = New System.Windows.Forms.TextBox()
Me.bnBrowseFolder = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.bnDoit = New System.Windows.Forms.Button()
Me.bnQuit = New System.Windows.Forms.Button()
Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.LinkLabel1 = New System.Windows.Forms.LinkLabel()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'folderName
'
Me.folderName.Location = New System.Drawing.Point(203, 366)
Me.folderName.Name = "folderName"
Me.folderName.Size = New System.Drawing.Size(304, 20)
Me.folderName.TabIndex = 0
'
'tbUserName
'
Me.tbUserName.Location = New System.Drawing.Point(203, 410)
Me.tbUserName.Name = "tbUserName"
Me.tbUserName.Size = New System.Drawing.Size(256, 20)
Me.tbUserName.TabIndex = 11
'
'bnBrowseFolder
'
Me.bnBrowseFolder.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bnBrowseFolder.Location = New System.Drawing.Point(519, 368)
Me.bnBrowseFolder.Name = "bnBrowseFolder"
Me.bnBrowseFolder.Size = New System.Drawing.Size(71, 19)
Me.bnBrowseFolder.TabIndex = 1
Me.bnBrowseFolder.Text = "Browse..."
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(115, 363)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(88, 24)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Folder Name:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'bnDoit
'
Me.bnDoit.Location = New System.Drawing.Point(131, 479)
Me.bnDoit.Name = "bnDoit"
Me.bnDoit.Size = New System.Drawing.Size(72, 48)
Me.bnDoit.TabIndex = 6
Me.bnDoit.Text = "Take Ownership"
'
'bnQuit
'
Me.bnQuit.Location = New System.Drawing.Point(255, 479)
Me.bnQuit.Name = "bnQuit"
Me.bnQuit.Size = New System.Drawing.Size(56, 48)
Me.bnQuit.TabIndex = 7
Me.bnQuit.Text = "Quit"
'
'FolderBrowserDialog1
'
Me.FolderBrowserDialog1.Description = "Select the directory that you want to use As the default."
Me.FolderBrowserDialog1.RootFolder = System.Environment.SpecialFolder.Windows
Me.FolderBrowserDialog1.ShowNewFolderButton = False
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(109, 406)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(88, 24)
Me.Label4.TabIndex = 12
Me.Label4.Text = "User Name: "
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Font = New System.Drawing.Font("Verdana", 21.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(125, 147)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(465, 35)
Me.Label2.TabIndex = 13
Me.Label2.Text = "SDE CSC FOLDER OWNERSHIP"
'
'PictureBox1
'
Me.PictureBox1.Image = Global.ChangeOwner.My.Resources.Resources.SDELogo_1_9_14
Me.PictureBox1.Location = New System.Drawing.Point(11, 12)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(255, 105)
Me.PictureBox1.TabIndex = 14
Me.PictureBox1.TabStop = False
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Font = New System.Drawing.Font("Verdana", 21.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(146, 182)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(426, 35)
Me.Label3.TabIndex = 15
Me.Label3.Text = "AND DATA RECOVERY TOOL"
'
'LinkLabel1
'
Me.LinkLabel1.AutoSize = True
Me.LinkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline
Me.LinkLabel1.Location = New System.Drawing.Point(56, 235)
Me.LinkLabel1.Name = "LinkLabel1"
Me.LinkLabel1.Size = New System.Drawing.Size(616, 78)
Me.LinkLabel1.TabIndex = 16
Me.LinkLabel1.TabStop = True
Me.LinkLabel1.Text = resources.GetString("LinkLabel1.Text")
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(734, 862)
Me.Controls.Add(Me.LinkLabel1)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.bnQuit)
Me.Controls.Add(Me.bnDoit)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.bnBrowseFolder)
Me.Controls.Add(Me.folderName)
Me.Controls.Add(Me.tbUserName)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "Form1"
Me.Text = "Change Owner"
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
Private Sub bnBrowseFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnBrowseFolder.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
Me.folderName.Text = FolderBrowserDialog1.SelectedPath
End If
End Sub
Private Sub bnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnQuit.Click
Me.Close()
End Sub
Sub HandleDir(directory As String, userName As String)
Try
ChangeOwner(directory, userName)
For Each subdir As String In System.IO.Directory.GetDirectories(directory)
HandleDir(subdir, userName)
Next subdir
Catch exception As System.Exception
System.Diagnostics.Debug.WriteLine(exception.Message)
End Try
End Sub
Private Sub bnDoit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnDoit.Click
Dim strPath As String
Dim strUser As String
If tbUserName.Text = "" Then
MsgBox("Please type your NMEA account name (eg. domain\administratoraccount)", MsgBoxStyle.Exclamation)
Exit Sub
End If
strPath = folderName.Text
strUser = tbUserName.Text
Try
'ChangeOwner(strPath, strUser)
HandleDir(Me.folderName.Text, strUser)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical)
Exit Sub
End Try
Dim dInfo As New DirectoryInfo(strPath)
Dim dSecInfo As DirectorySecurity = dInfo.GetAccessControl(AccessControlSections.All)
Dim myRuleValue As Integer = 0
myRuleValue = FileSystemRights.FullControl 'Add your wanted Access here
Dim myRule As New FileSystemAccessRule(strUser, myRuleValue, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow)
dSecInfo.AddAccessRule(myRule)
dSecInfo.SetAccessRule(myRule)
dInfo.SetAccessControl(dSecInfo)
MessageBox.Show("Finished!")
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "SDE CSC FOLDER OWNERSHIP AND DATA RECOVERY TOOL"
Me.BackColor = Color.LightSteelBlue
Me.Size = New Size(750, 900)
Me.Location = New Point(100, 40)
Me.MaximizeBox = False
End Sub
End Class
|
|
|
|
|
You're welcome, glad it helped
|
|
|
|
|
Good day friends! I have been surfing the net for some days now but all yield no result. This is what I want; I created autorun file in text file for my vb app and place the app along with the autorun file in the root directory of my flash drive. When I plugged the flash in my pc using win 7 OS, my expectation failed. The program didn't run rather the normal dialog appeared asking what I want to do with the flash. The question is how could I achieve this in win 7 OS? Thanks in advance,
|
|
|
|
|
Windows Vista disabled auto run as it was a security risk. So Win7 has it disabled as well. There is no way to enable it again, either.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
There is no way to get around that dialog box. One of the options, I think, is to execute the autorun, but I could be wrong. I haven't used it in a long time.
|
|
|
|
|
From a security perspective, I will NEVER autorun an application on a flash drive.
I've seen an entire network get a virus from a flash drive.
|
|
|
|
|
I have database like this
Manufacture Model No Length Width height
Manufacture 1 MD-01 200 300 100
Manufacture 1 MD-02 300 400 100
Manufacture 1 MD-03 400 300 150
Manufacture 2 MAD-01 200 450 100
Manufacture 2 MAD-02 250 400 100
Manufacture 3 MDI-01 300 300 100
Manufacture 4 MOv-01 350 300 100
I would like to create 2 combobox -
1) Manufacture 2 ) model No
Manufacture should display for above example Manufacture 1,Manufacture 2,Manufacture 3, Manufacture 4
when particular manufacture selected for example Manufacture 2 -> combox should display only MAD-01 & MAD 02.
Based on both selection text box must me loaded with length, width , height.
i tried sample code & try to assign the combox with database value. I found duplicate list of column. Like for combobox1 accumulate
Manufacture 1
Manufacture 1
Manufacture 1
Manufacture 2
Manufacture 2
Manufacture 3
Manufacture 4
Is there any example program available to do this. How can do this.
|
|
|
|
|
You have to create separate data sources for these and bind the dropdowns to them. You'll have to execute a Distinct Select on whatever columns from the datasource you're trying to bind to.
|
|
|
|
|