
dynamic_sysop
Leaders
-
Posts
1044 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by dynamic_sysop
-
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Button6_Click(sender, e) End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click MessageBox.Show(sender.Name) End Sub in that case the messagebox would show "Button5" if you raised the Button6_Click event from Button5. hope that helps.
-
Can a control name be referred to by a variable?
dynamic_sysop
replied to HDokes's topic in Windows Forms
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim x As Control For Each x In Me.Controls If TypeOf x Is Button Then x.Text = "new text" End If Next End Sub if you wanted to make them all have a different name, you'd have to make a loop and a string as the button name or something. like this : Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Dim arrButtons As New ArrayList() Dim i As Integer Dim strButton As String = "Button" Dim btn As Control For i = 0 To 6 arrButtons.Add(strButton & i) For Each btn In Me.Controls If btn.Name = arrButtons(i) Then btn.Text = "item: " & i End If Next Next End Sub -
Hi guys , i've been working on an easier way to load a form and send info back to the starting form / another form. there's no need to modify the Sub New really , this is all you need to do : from the form you already have open to call the second form : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frmKid As New Form3() Me.AddOwnedForm(frmKid) frmKid.Show() End Sub from the second form ( eg: Form2 ) to set some text in Form1's Textbox : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frmBoss As Form1 = Me.Owner frmBoss.TextBox1.Text = "test" '///put some text in Form1's textbox. End Sub i think this may save a bit of messing for people :)
-
Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter Label1.Focus() '/// now you wont see a cursor. End Sub :)
-
if you have a textbox on Form1 and you want to change it's text from Form2 , you can do this : at top of Form2 , modify the Public Sub New() Public Class Form2 Inherits System.Windows.Forms.Form Public frm As Form1 '/// first make a public reference to your form ( eg: Form1 ) #Region " Windows Form Designer generated code " Public Sub New(ByVal myForm As Form) '/// make myForm as a Form ( not Form1 ) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() frm = myForm '/// initialize the instance of the form as Form1. 'Add any initialization after the InitializeComponent() call End Sub from a command button on Form2 : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click frm.TextBox1.Text = "i am some text from form2 to form1's textbox!" End Sub to show the Form2 , do this in Form1 : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frmTwo As New Form2(Me) frmTwo.Show() End Sub
-
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown Label1.Focus() '/// move focus to another control to prevent cursor showing End Sub Private Sub TextBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseUp Label1.Focus() End Sub that stops the cursor showing in the textbox , also it prevents it being edited even if readonly is false.
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click With TextBox2 .ForeColor = Color.Red '///set the text colour to red .Text = TextBox1.Text '/// add the text to the new textbox End With TextBox1.Text = "" '///clear the old textbox End Sub
-
you need to specify the table , rather than just "Ds" i think . eg: 1 of my form's i can update the datagrid to show the table i wish like this : DBAdapt.Fill(DBset, "UserTable") DataGrid1.DataSource = DBset.Tables("UserTable")'/// update the datagrid to hold the new dataset. hope this helps.
-
How to transfer data from a called form to the main form controls
dynamic_sysop
replied to HDokes's topic in Windows Forms
here's a quick example : in form2 ( the form you want to send information from, to form1 ) Public Class Form2 Inherits System.Windows.Forms.Form Public frm As Form1 '/// first make a public reference to a new form #Region " Windows Form Designer generated code " Public Sub New(ByVal myForm As Form) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() frm = myForm '/// initialize the form 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. 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 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Button1 As System.Windows.Forms.Button <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button() Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(136, 104) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 0 Me.Button1.Text = "Button1" ' 'Form2 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1}) Me.Name = "Form2" Me.Text = "Form2" Me.ResumeLayout(False) End Sub #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click frm.TextBox1.Text = "i am some text from form2 to form1's textbox!" End Sub End Class in Form1 ( the form you want to start up with ) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frmTwo As New Form2(Me) frmTwo.Show() End Sub -
Help --> Connect to a DataBase
dynamic_sysop
replied to comcrack's topic in Database / XML / Reporting
the tables "binFrm" and "Addresses" are in 1 of my databases thats why:-\ that was an example showing how to open the tables , you would put your table names inplace of them:) -
Help --> Connect to a DataBase
dynamic_sysop
replied to comcrack's topic in Database / XML / Reporting
you could try something like this : Public Function OpenAccess(ByVal strConn As String, ByVal strComm As String) Dim i As Integer, x As Integer Dim DBCon As New OleDbConnection(strConn) DBCon.Open() Dim DBCommand As New OleDbCommand(strComm, DBCon) Dim DBAdapt(2) As OleDbDataAdapter '/// make an array of each table in your database. DBAdapt(1) = New OleDbDataAdapter(DBCommand) DBAdapt(2) = New OleDbDataAdapter(DBCommand) Dim DBset As New DataSet() DBAdapt(1).Fill(DBset, "binFrm") DBAdapt(2).Fill(DBset, "Addresses") For i = 0 To DBset.Tables.Count - 1 For x = 0 To DBset.Tables.Item(i).Columns.Count - 1 Dim strTable As String = DBset.Tables.Item(i).TableName Dim strColumn As String = DBset.Tables.Item(i).Columns(x).ColumnName MessageBox.Show("the tabel: " & strTable & " Contains the following Columns:" & Chr(10) & strColumn) Next Next DBCon.Close() DBCommand.Dispose() DBAdapt(1).Dispose() DBAdapt(2).Dispose() DBset.Dispose() End Function -
Help --> Connect to a DataBase
dynamic_sysop
replied to comcrack's topic in Database / XML / Reporting
top of your form's code window you need this : Imports System.Data.OleDb then you can do the following , making sure you specify your .mdb's location and table etc... Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:/bin.mdb" Dim strCommand As String = "SELECT * FROM binFrm" OpenAccess(strconnection, strCommand) End Sub Public Function OpenAccess(ByVal strConn As String, ByVal strComm As String) Dim DBCon As New OleDbConnection(strConn) DBCon.Open() Dim DBCommand As New OleDbCommand(strComm, DBCon) Dim DBAdapt As New OleDbDataAdapter(DBCommand) Dim DBset As New DataSet() DBAdapt.Fill(DBset, "binFrm") DataGrid1.DataSource = DBset.Tables("binFrm") '/// add the entire access database to a datagrid. DBCon.Close() DBCommand.Dispose() DBAdapt.Dispose() DBset.Dispose() End Function hope that helps. -
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strBuffer As String = "A=100,V=12,P=T,A=121,V=10" Dim strArray() As String = Split(strBuffer, ",") Dim strLeft As String Dim x As Integer For x = 0 To UBound(strArray) strLeft = Split(strArray(x), "=")(0) Select Case strLeft Case "A" MessageBox.Show("A has a value of: " & Split(strArray(x), "=")(1)) '// your code here for checkboxes etc... Case "V" MessageBox.Show("V has a value of: " & Split(strArray(x), "=")(1)) Case "P" MessageBox.Show("P has a value of: " & Split(strArray(x), "=")(1)) End Select Next End Sub hope that helps a little.
-
well this will retrieve the value of the item you clicked on : Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp Dim i As Integer = DataGrid1.CurrentRowIndex Dim j As Integer = DataGrid1.CurrentCell.ColumnNumber MessageBox.Show(DataGrid1.Item(i, j)) End Sub
-
Excel Startup Problems
dynamic_sysop
replied to RazerWriter's topic in Interoperation / Office Integration
i'm using 10.0 but this may help , i think you should try setting the excel sheet as the item thats opening the app , like this : Dim exExcel As New Excel.Application() Dim exSheet As Excel.Workbook Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click exSheet = exExcel.Workbooks.Open("C:\Book1.xls") MsgBox(exSheet.Sheets.Count) '///just to check the excel app did open End Sub -
sorry VolteFace , my spelling goes off after 8pm these days:-\ i generaly use Process so that i can handle it's events after , ie : closing the process from a list and stuff so i just go about it that way, i didnt know that you could just put the link in without IEXPLORE , so i learnt something myself lol.
-
as voltface says use Process.Start , you could use a link label and do the following : Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked Dim proc As Process = New Process() e.Link.Visited = True '///make the link look like a clicked link in internet explorer. proc.Start("IEXPLORE", LinkLabel1.Text) '///launch an instance of internet explorer and navigate to the link off the label. End Sub
-
here's an idea , put a panel on your form , set it so it's left is something like -150 ( depending on the width of the panel ) then do this : Public OldPanelPos As Integer '/// public variable. Private Sub Panel1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.MouseEnter Dim x As Integer OldPanelPos = Panel1.Left For x = OldPanelPos To 0 Panel1.Left = x Next End Sub Private Sub Panel1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.MouseLeave Panel1.Left = OldPanelPos End Sub then the panel will slide on to the form , from being just sticking out. then you could add options on to the panel as menu's.
-
Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp ListView1.FocusedItem.Selected = True End Sub hope that helps :)
-
you can use a few ways System.Environment.NewLine '// return Chr(10)'/// also starts a new line Chr(13)'/// so does this VbCrlf'/// from visual basic , but still works
-
i have put together yet another way of getting the char at the position the cursor stopped at in the richtextbox : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click With RichTextBox1 .ScrollToCaret()'/// get the cursor ( selection start ) .SelectionLength = 1'/// get the char ( s ) you want, 1 retrieves the first char. MessageBox.Show(.SelectedText) End With End Sub
-
the twins are due in august , but my wife has been in hospital already so they may come sooner :-\
-
here ya go , you would have to account for how many forms you have , but you should get the idea : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim str(2) As String, x As Integer Dim strLocation As String = Application.StartupPath strLocation = Replace(strLocation, "bin", "") str(1) = strLocation & "Form1.vb" : str(2) = strLocation & "Form2.vb" Dim sr(2) As StreamReader For x = 1 To 2 sr(x) = New StreamReader(New FileStream(str(x), FileMode.Open)) TextBox1.Text = sr(x).ReadToEnd() MessageBox.Show("The Number of Lines in " & str(x) & " is:" & Chr(10) & TextBox1.Lines.Length) sr(x).Close() Next End Sub
-
Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click Dim ClientID As String = ListView1.SelectedItems(0).Text MessageBox.Show(ClientID) End Sub
-
here ya go , not sure if this is what you want , but when you move the cursor over the richtextbox it will return the character under the cursor : Private Sub RichTextBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseMove Me.Text = GetWordUnderCursor(e.X, e.Y) '/// get the current letter by cursor position. End Sub Public Function GetWordUnderCursor(ByVal X As Integer, ByVal Y As Integer) As String Dim point As System.Drawing.Point = New System.Drawing.Point() point.X = X point.Y = Y Dim c As Char = RichTextBox1.GetCharFromPosition(point) Return c End Function