
dynamic_sysop
Leaders
-
Posts
1044 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by dynamic_sysop
-
you'd be much better off using streamreader / writer. eg: Imports System.IO '/// at top of your code window^^^^ '/// Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Thefile As String = "C:\test.txt" FileScan("", Thefile) End Sub Sub FileScan(ByVal str As String, ByVal strFileTitle As String) Dim strReader As StreamReader = New StreamReader(New FileStream(strFileTitle, FileMode.Open)) str = strReader.ReadLine While strReader.Peek <> -1 '/// your sorting code here TextBox1.AppendText(str) str = strReader.ReadLine End While strReader.Close() End Sub putting something like your line's text from the database where it says "FileScan("", Thefile)" and then you could do an if else , like this : Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim Thefile As String = "C:\test.txt" Dim TheLine As String = "testing 123" '/// your text to compare here. FileScan(TheLine, Thefile) End Sub Sub FileScan(ByVal str As String, ByVal strFileTitle As String) Dim strReader As StreamReader = New StreamReader(New FileStream(strFileTitle, FileMode.Open)) If str = strReader.ReadLine Then MsgBox("you already have that line!") str = "" Else str = strReader.ReadLine End If While strReader.Peek <> -1 TextBox1.AppendText(str) str = strReader.ReadLine End While strReader.Close() End Sub
-
Selected Listview Item (code vs. mouseclick)
dynamic_sysop
replied to Heiko's topic in Windows Forms
i dont think you will highlight the listitem in the same way as clicking it, i think thats a WM_PAINT issue that happens when the mouse goes down, focusing / selecting the item will only highlight it a dull grey colour not dark blue / grey -
i found that DateDiff doesnt work in C# ( although you can implement it through a lot of code ) so i thought i'd have a mess with TimeSpan , here's a working example for calculating differences of date / time in C# with timespan : private void button1_Click(object sender, System.EventArgs e) { try { string strDate="10/06/2003 10:20:15"; string strFinish="11/06/2003 18:28:37"; string MsgDay="Difference in Days:\n"; string MsgHour="\nDifference in Hours:\n"; string MsgMins="\nDifference in Minutes:\n"; TimeSpan s=Convert.ToDateTime(strFinish).Subtract(Convert.ToDateTime(strDate)); MessageBox.Show(MsgDay+s.TotalDays.ToString()+MsgHour+s.TotalHours.ToString()+MsgMins+s.TotalMinutes.ToString()); } catch { System.Exception f = new System.Exception(); MessageBox.Show(f.Message); } }
-
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim sr As StreamReader = New StreamReader(New FileStream("C:\test.ini", FileMode.Open)) TextBox1.AppendText(sr.ReadToEnd) sr.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim sw As StreamWriter = New StreamWriter(New FileStream("C:\test.ini", FileMode.Create)) sw.WriteLine(TextBox1.Text) sw.Close() End Sub you can add your ini file to the texbox upon clicking button2 then make your changes to the text in the textbox , click button3 and it will update you ini file .
-
Private Declare Sub GetSystemInfo Lib "kernel32.dll" (ByRef lpSystemInfo As SYSTEM_INFO) Private Structure SYSTEM_INFO Public dwOemID As Int32 Public dwPageSize As Int32 Public lpMinimumApplicationAddress As Int32 Public lpMaximumApplicationAddress As Int32 Public dwActiveProcessorMask As Int32 Public dwNumberOrfProcessors As Int32 Public dwProcessorType As Int32 Public dwAllocationGranularity As Int32 Public dwReserved As Int32 End Structure Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s As SYSTEM_INFO GetSystemInfo(s) MsgBox(s.dwProcessorType & Chr(10) & s.dwNumberOrfProcessors & Chr(10) & s.dwPageSize) End Sub
-
DateDiff calculation not displaying in text box
dynamic_sysop
replied to Lan Solo's topic in General
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim strStart As String = "11/06/2003 09:10:45" Dim strCurrent As Date Dim mintNumberOfDays As Integer = DateDiff(DateInterval.Day, Convert.ToDateTime(strStart), strCurrent.Now) MessageBox.Show("the date difference is : " & mintNumberOfDays) End Sub -
this is the correct method to open your file and get it to fill your chosen textbox / rtfbox : Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim streamtodisplay As StreamReader = New StreamReader(New FileStream("C:\test.txt", FileMode.Open)) With rtfBox .AppendText(streamtodisplay.ReadToEnd) '/// add the textfile to the box End With streamtodisplay.Close() End Sub
-
to ole or not to ole, that is the question.
dynamic_sysop
replied to mercicle's topic in Interoperation / Office Integration
you could try this : Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click With rtfBox .Find(TextBox1.Text) .SelectedText = "" End With End Sub or this would get rid of them all in 1 go : Dim str() As String, s As String, i As Integer s = rtfBox.Text str = Split(s, Chr(32)) For i = 0 To UBound(str) If str(i) = TextBox1.Text Then rtfBox.Text = Replace(rtfBox.Text, str(i), " ") End If Next -
what sort of dropdown list ? like a combobox dropdown? Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ComboBox1.Items.Add("text here") End Sub Private Sub ComboBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.Click Label1.Text = ComboBox1.SelectedText End Sub
-
Dim ctl As Control Dim obj As String = "TextBox1" For Each ctl In Me.Controls If ctl.Name = obj Then MsgBox(ctl.Name & Chr(10) & ctl.Text) Else MsgBox(ctl.Name) End If Next or if you want to get the controls on your form by Type and list them / get the handles : Dim ctl As Control For Each ctl In Me.Controls If TypeOf ctl Is TextBox Then MessageBox.Show("textbox : " & ctl.Handle.ToInt32 & Chr(10) & ctl.Name) Else MessageBox.Show("other control : " & ctl.Handle.ToInt32 & Chr(10) & ctl.Name) End If Next
-
i might try that way to see how it works , i created another way which does work : Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim f As Control For Each f In Form1.ActiveForm.Controls '// form's name If TypeOf f Is ComboBox Then clearBox(f) ElseIf TypeOf f Is ListView Then ClearListView(f) End If Next End Sub Public Sub clearBox(ByVal cb As ComboBox) cb.Items.Clear() End Sub Public Sub ClearListView(ByVal lv As ListView) lv.Items.Clear() End Sub
-
MsgBox(DateDiff(DateInterval.Hour, Date.Now, Convert.ToDateTime("11/06/2003 21:01:33"))) in your case putting the times as ness. but this only calculates the difference in hours not the minutes / seconds so you'll get 0 with the 2 times you got there. this will give you the diff for seconds : Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim tSTime As String = "14:25:45" Dim tETime As String = "14:27:40" MsgBox(DateDiff(DateInterval.Second, Convert.ToDateTime(tETime), Convert.ToDateTime(tSTime))) End Sub this for minutes : Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim tSTime As String = "14:25:45" Dim tETime As String = "14:27:40" MsgBox(DateDiff(DateInterval.Minute, Convert.ToDateTime(tETime), Convert.ToDateTime(tSTime))) End Sub and they will sort you out with your problem.
-
how to make a mouseover effect in the textbox?
dynamic_sysop
replied to elf's topic in Windows Forms
Private Sub TextBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox2.MouseDown If e.Button = MouseButtons.Left Then TextBox2.Text = "" End If End Sub -
well the answer to your enter key problem is this : Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = 13 Then TextBox2.Focus() End If
-
what exactly have you got stored in the treeview? are you wanting to say click on an item like this : "i'm some text in a treeview" and get back this : "i'm some text"
-
'//Imports WindowsApplication1.Module1 << ignore Imports System.IO '///top of form's code window Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Private Const EM_GETLINECOUNT As Integer = CInt(&HBA) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim sr As StreamReader = New StreamReader(New FileStream("C:\Documents and Settings\den\My Documents\Visual Studio Projects\WindowsApplication1\Form1.vb", FileMode.Open), True) TextBox1.AppendText(sr.ReadToEnd.ToString()) i = SendMessage(TextBox1.Handle.ToInt32, EM_GETLINECOUNT, 0, 0) MsgBox(i) '/// i will return the line count of form1 sr.Close() End Sub you would have to repeat the procedure for each form :) i'm glad that worked :p
-
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click MsgBox(TextBox1.SelectionStart) End Sub returns the current value , eg: if your textbox contains "test" and the cursor is flashing in between the "te" and "st" it would return 2
-
if you set the form to be your clipboard viewer it doesnt matter about having focus , because if you are listening for changes on the clipboard these messages will pass through your form anyway. so whenever the data changes you should get notified of it.
-
erm that form1_kepress looks a bit hey wire :-\ is it supposed to say handles button1.keypress when it's a form keypress event ? the correct format for form keypress is this ... Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress End Sub
-
this will stop users being able to use ctrl and an arrow key to scroll through the tabs Private Sub TabControl1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TabControl1.KeyDown If e.KeyCode = 17 Or e.KeyCode = 37 Or e.KeyCode = 39 Then Button1.Focus() End If End Sub Private Sub TabControl1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TabControl1.KeyUp If e.KeyCode = 17 Or e.KeyCode = 37 Or e.KeyCode = 39 Then Button1.Focus() End If End Sub note : i am setting focus to another object ( a button in this case ) hope this helps.
-
i think the upgrade wizard is the worst thing in .net , how are people going to learn the code if they can click a button and convert from vb to .net:-\ i only used it a couple of times and that was 2 times 2 many. but: if anyone does use it, you can cut down on the error's / upgrade issues by declaring your code correcly in vb , eg: instead of doing this ... Dim i, j do this... Dim i As Integer Dim j As Integer also if you have declares using "as any" change them to an appropriate alternative and change "long" to "integer" in them eg: Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long change it to : Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Integer) As Integer this cuts down on the upgrade issues when you do convert.
-
just a thought but couldnt you try something like this code i bunged together : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Ctrls(0) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Ctrls(1) End Sub Public Sub Ctrls(ByVal i As Integer) Dim btns() As Button = {Button1, Button2} Select Case i Case 0 MessageBox.Show("you clicked button index " & i.ToString()) Case 1 MessageBox.Show("you clicked button index " & i.ToString()) End Select End Sub
-
cheers volt :) that inspired me using System.Runtime.InteropServices; /// top of form ^^^ /// /// [DllImport("User32.Dll")] public static extern int SendMessage(int hwnd,int wMsg,int wParam,int lParam); public const int PBM_SETBKCOLOR = 0x2001; public const int PBM_SETBARCOLOR = 0x409; //// in design area ( below ) ^^^^ //// public void SetProgressBackColor(Color c) {/// set the back color of the bar int a=Convert.ToInt32(c.R.ToString()); int b=Convert.ToInt32(c.G.ToString()); int d=Convert.ToInt32(c.B.ToString()); int tot=Convert.ToInt32(ColorTranslator.ToOle(Color.FromArgb(a,b,d)).ToString()); int j=this.progressBar1.Handle.ToInt32(); SendMessage(j,PBM_SETBKCOLOR,0,tot); } public void SetProgressForeColor(Color c) {/// set the forecolor of the bar int a=Convert.ToInt32(c.R.ToString()); int b=Convert.ToInt32(c.G.ToString()); int d=Convert.ToInt32(c.B.ToString()); int tot=Convert.ToInt32(ColorTranslator.ToOle(Color.FromArgb(a,b,d)).ToString()); int j=this.progressBar1.Handle.ToInt32(); SendMessage(j,PBM_SETBARCOLOR,0,tot); } private void button4_Click(object sender, System.EventArgs e) { SetProgressBackColor(System.Drawing.Color.BlueViolet); SetProgressForeColor(System.Drawing.Color.Red); } :) thanks again for the help.
-
ok if i elaberate a little with what i'm making maybe a suggestion on how to change the colours. i have adapted my vb6 coding for changing progressbar colours ( front and back ) to C# [DllImport("User32.Dll")] public static extern int SendMessage(int hwnd,int wMsg,int wParam,int lParam); public const int PBM_SETBKCOLOR = 0x2001; public const int PBM_SETBARCOLOR = 0x409; private void button4_Click(object sender, System.EventArgs e) { int j=this.progressBar1.Handle.ToInt32(); //get handle for progressbar SendMessage(j,PBM_SETBKCOLOR,0,10); //set backcolor of progressbar SendMessage(j,PBM_SETBARCOLOR,0,255); //set forecolor of progressbar } in that case the 10 sets the backcolor to black , the 255 sets the forecolor to red. i want to be able to allow a change of colour where the user can actually tell what colour they are setting rather than a number that means nothing to them.
-
i seem to get an error with that, cannot convert int[] to int. so i tried messing with it a bit, but Argb seems to be returning something funny lol System.Int32[] thats what Argb is showing as.