|
Yes i did, but that didn't work... So i removed all registry entries that pointed to the ocx and registrated the new one. That didn't work too.
My last hope was a system restart, did it, and YES it works again!!!
Don't know what fixed the problem, but my solutions where:
- Recompiling the ocx on the other computer.
- Registrating all dll/ocx files again.
- Removed all registry entries of the ocx file.
- Registrated the ocx again.
- Restarted the computer.
|
|
|
|
|
I have a ContextMenuStrip that I am showing programmatically in response to a button being clicked. Everything works as expected, except that the Items in the menu do not respond to being moused over. Whether the mouse button is up or down, mousing over the menu has no visible effect, and releasing the mouse button does not select an Item, as expected. Performing a full click on an Item does still activate the Item, however.
Here's my code for showing the ContextMenuStrip:
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseDown(e)
If Enabled Then
m_MouseDown = True
If m_State > ButtonState.MousePressed Then
m_State = ButtonState.MousePressed
End If
Invalidate()
If DropDown IsNot Nothing AndAlso DropDown.Items.Count > 0 Then
If ShowMenu Then
ShowMenu = False
ElseIf arrowRect.Contains(PointToClient(MousePosition)) Then
ShowMenu = True
m_MouseHeldWhileOpened = True
DropDown.Capture = True
End If
End If
End If
End Sub
Protected Property ShowMenu() As Boolean
Get
Return m_showMenu
End Get
Set(ByVal value As Boolean)
If value <> m_showMenu Then
m_ShowMenu = value
If m_ShowMenu Then
m_DropDown.Show(Me, GetDropDownSpawnPoint, DropDownDirection)
m_State = ButtonState.MenuUp
If m_DropDown.ClientRectangle.Contains(PointToScreen(MousePosition)) Then
m_DropDown.Capture = True
End If
Else
m_DropDown.Close()
ElevateState()
End If
End If
End Set
End Property
I have tried a number of different ideas to get the menu to respond correctly, some of which attempts are still evident in the code here. If any help would be forthcoming, it would be greatly appreciated - nobody else on Google seems to have experienced this problem.
Thank you in advance for any help you can offer.
|
|
|
|
|
What are you trying to do that you have all this code in the mousedown events?
Whenever i have used context menu's in the past i haven't gone to all that trouble.
For example, the code below is handles on a button.click, It creates a new context menu, adds to click handlers for the menus events and shows the menu next to the button.
Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
Dim theMenu As New ContextMenuStrip
theMenu.Items.Add("Export to XML", MenuExportXML.Image, AddressOf MenuExportXML_Click)
theMenu.Items.Add("Export to CSV", MenuExportCSV.Image, AddressOf MenuExportCSV_Click)
Dim p As New Point
p.X = ButtonSave.Width
p.Y = ButtonSave.Top
theMenu.Show(ButtonSave, p)
End Sub
|
|
|
|
|
Hi,everyone,now I need to write some texts to some cells with VB.NET ,sometimes I need the texts wrote in two lines or three lines in one cell.Just like below:
"ABCDEFG" ,in the cell it should like
ABC
DEFG
That is the question:could I control it with VB.NET?
Need some help or sugestion,Thanks a lot!
|
|
|
|
|
you did not say on what surface, in what Control, where at all this is going on.
Some Controls simply accept multi-line text and perform wrapping themselves; most of those also understand Environment.NewLine; some have a property you'd have to set true before they accept multi-line text; and some don't at all.
PS: all of them would tell you in the documentation, all it takes is to go to the appropriate page; I can't provide a link as I'm in the dark of the very nature of your cells.
|
|
|
|
|
I feel very very sorry for my carelessness that made you perplexed.What I wanted to say was "EXCEL cells" and the text came from some VB.NET controls such as TEXTBOX or COMBOBOX.
Luc,could you give me some suggestion now?THX!
|
|
|
|
|
I haven't done this myself, however I think "abc\ndef" will show as two lines in a single Excel cell if the cell formatting allows wrapping.
|
|
|
|
|
Since you're speaking about cells without additonal information I assume you might mean Excel cells. In that case I'd suggest to use VBA, which is integrated into Excel. Using VB.NET wouldn't make a lot of sense. Maybe you let us know more, we're only guessing here.
|
|
|
|
|
oh,I'm very very sorry for my carelessly! What I really want to say was "EXCEL CELLS"…
It seams that the problem only could be done with VBA…Em…I will try it .Thank you!
|
|
|
|
|
Hi, Dave's (the next) answer is exactly what I would have suggested.
Still I don't understand when you say the text comes from VB.NET controls - would that mean you would first have to grab the text from a different program? In that case it's a much (muchmuch!) harder job to do, so I hope I'm misinterpreting that remark . If you wanted to say "VBA controls" instead (i.e. inside Excel) then again it's something you can manage without going insane
|
|
|
|
|
While working in excel directly not via code, you can use ALT+Enter keystroke to achieve this.
While using code it is as simple as inserting a Carriage Return and Line feed into the string.
Private Sub doSomething()
Dim xlApp As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application()
Dim xlWk As Microsoft.Office.Interop.Excel.Workbook = xlApp.Workbooks.Add()
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet = xlWk.Worksheets(1)
xlApp.Visible = True
xlSheet.Range("A1").Value = "Some Text Value on 1 line"
xlSheet.Range("A5").Value = "Some text value on" + vbCrLf + "2 lines"
xlSheet.Columns().AutoFit()
xlSheet.Rows().AutoFit()
End Sub
|
|
|
|
|
Hi,
Is it possible to create a new instance of a control if I only has the type of it?
E.g. Type of Button -> new instance of button
|
|
|
|
|
What other information do you think you might need?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
look for Activator.CreateInstance(), that works a lot easier than full reflection, where you would invoke a constructor.
|
|
|
|
|
Thanks
|
|
|
|
|
Hi all,
I'm using a BackgroundWorker to create a file list. It's started with BG1.RunWorkerAsync() in the Changed-Event of a form control, and for the purpose of testing I show a messagebox at the end of the BG1.RunWorkerCompleted event. This works fine.
But it doesn't seem so easy to re-use the same BackgroudWorker for the same task. Wanting to start the same BGW again (in another controls Changed-event) and with the same command (BG1.RunWorkerAsync() ) throws an InvalidOperationException telling me that the respective BackgroundWorker was still busy and couldn't handle multiple tasks at a time.
What's wrong here? I'm sure the messagebox is the last command in the RunWorkerCompleted event, and it has of course been closed before clicking the control which is supposed to restart the BGW. Would I have to dispose of the BGW and create it newly?
Thank you for advice,
Michael
|
|
|
|
|
Hi,
I've never felt a need to reuse an existing BackgroundWorker; once it is done, I forget about it; and I create a new one when needed. The expensive part of a BGW is the thread itself (and its associated stack), however that thread is borrowed from the ThreasPool so it gets recycled in an inexpensive way.
|
|
|
|
|
Didn't you use this condition If BG1.IsBusy = False Then before call BG1.RunWorkerAsync() ?
Use <pre lang="vb"> Visual Basic Code Here.</pre>
|
|
|
|
|
Thank you for having a look at this old - yet unresolved - thread.
I had thought about what you suggest, but checking IsBusy this way would just skip the task, since I found out that BG1 is busy in the respective moment. So, considering my intention to use the BG1 for a similar task again, the only way to use the IsBusy flag could be looping until the flag would become false. Not knowing how long BG1 would be busy after 'RunWorkerCompleted' (which was actually my question), this seemed to be a waste of time - so I started experimenting with the ThreadPool, which worked but is a different chapter again because of an obviously huge overhead.
If you're experienced in this field, I'd really appreciate an idea how to simply copy a filelist as fast or even faster using .NET than using a DOS batch file.
Thanks
Michael
|
|
|
|
|
Hi,
Just watch the following example & mark the point where is your problem.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim BG As New System.ComponentModel.BackgroundWorker
BG.WorkerReportsProgress = True
AddHandler BG.DoWork, AddressOf BackgroundWorker_DoWork
AddHandler BG.RunWorkerCompleted, AddressOf BackgroundWorker_RunWorkerCompleted
AddHandler BG.ProgressChanged, AddressOf BackgroundWorker_ProgressChanged
Static Cnt As Integer = 1
BG.RunWorkerAsync(Cnt)
Cnt = Cnt + 1
End Sub
Private Sub BackgroundWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
Dim stp As New Stopwatch
stp.Start()
Do
If stp.ElapsedMilliseconds Mod 1000 = 0 Then
CType(sender, System.ComponentModel.BackgroundWorker).ReportProgress(stp.ElapsedMilliseconds, e.Argument)
Threading.Thread.Sleep(100)
End If
Loop
End Sub
Private Sub BackgroundWorker_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs)
TextBox1.AppendText(e.UserState.ToString & "->" & e.ProgressPercentage & ", ")
End Sub
Private Sub BackgroundWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs)
End Sub
End Class
Michael Schäuble Wrote:
If you're experienced in this field, I'd really appreciate an idea how to simply copy a filelist as fast or even faster using .NET than using a DOS batch file.
Follow the link to copy files using explorer.exe without any testion. It is much more faster than .NET can do. All of the APIs & Constants are not needed. If you want handle copying files yourself you should use binary file read and write operation. That is much faster than DOS batch or Explorer. Like time and space complexity, you should choose what to do. Develop binary file copyer OR use Explorer or .NET Built-in classes.
http://www.codeproject.com/Messages/3526402/Re-Is-it-the-right-approach-to-speed-up-the-copy-p.aspx[^]
Use <pre lang="vb"> Visual Basic Code Here.</pre>
|
|
|
|
|
I am trying to store a word document to an image field in SQL. I get the file to send to SQL using the first code below. The problem is that when I try to load the field into a Word document using the second code, it is corrupted. I am thinking that it has something to do with encoding, but not sure. Can someone please help? Thanks in advance.
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myStream As Stream = Nothing
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
openFileDialog1.Title = "Save File to SQL"
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
myStream = openFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
Dim MyData(myStream.Length) As Byte
myStream.Read(MyData, 0, (myStream.Length))
Me.TowerTableAdapter.Add_LOTO(MyData, Me.Monsanto_Equip_NoTextBox.Text.ToString)
Me.TextBox3.Text = myStream.Length
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
Finally
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Try
End If
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim axWord As Word.Application
axWord = New Word.Application
axWord.Visible = True
Dim axDoc As Word.Document
axDoc = axWord.Documents.Add
Dim strText As String
strText = axDoc.Paragraphs(1).Range.Text
Dim conn = New SqlConnection(My.Settings.Maintenance_ManagementSQLConnectionString)
Dim EQ As String = Me.Monsanto_Equip_NoTextBox.Text.ToString
Dim AreaCMD As New SqlCommand()
AreaCMD.Connection = conn
AreaCMD.CommandText = "SELECT LOTO FROM [tower]where [monsanto equip no] = '" & EQ & "'"
conn.Open()
Dim AR As SqlDataReader = AreaCMD.ExecuteReader(CommandBehavior.SequentialAccess)
While AR.Read()
Dim binaryStream As SqlBinary = AR.GetSqlBinary(0)
Dim test As String = System.Text.Encoding.Unicode.GetString(binaryStream)
axDoc.Paragraphs(1).Range.Text = test.ToString
End While
conn.Close()
End Sub
|
|
|
|
|
Hi,
you can store binary data in an SQL field of type BLOB (and maybe others as well). It doesn't really matter what the meaning of the data is, all you can do is store it, and later retrieve it in basically the same way.
For a Word file that would mean getting all the bytes from a file, and writing them to the database; and later getting them from the database, and recreating the Word file. No more, no less.
I can't really see how you're writing to the database, as this is hidden inside the Me.TowerTableAdapter.Add_LOTO() method. I guess it is pretty straightforward.
However I have never seen a way to feed the file content as a stream to Word. So in my books the part containing
Dim test As String = System.Text.Encoding.Unicode.GetString(binaryStream)
axDoc.Paragraphs(1).Range.Text = test.ToString
is a no no.
Write the bytes to a new, possibly temporary file, then open that file with Word, probably using the Process.Start() method.
|
|
|
|
|
Hi Luc,
I have also tried this code that I think is what you are talking about. When I try to open the Word doc that is in the temp folder, it tells me that it is corrupt. It does however do a recovery and the document opens fine.
Dim conn = New SqlConnection(My.Settings.Maintenance_ManagementSQLConnectionString)
Dim EQ As String = Me.Monsanto_Equip_NoTextBox.Text.ToString
Dim AreaCMD As New SqlCommand()
Dim wordDoc As Byte()
AreaCMD.Connection = conn
AreaCMD.CommandText = "SELECT LOTO FROM [tower]where [monsanto equip no] = '" & EQ & "'"
conn.Open()
wordDoc = AreaCMD.ExecuteScalar()
File.WriteAllBytes("C:\Temp\WordDoc.docx", wordDoc)
|
|
|
|
|
A simple check: do the input and output file have the same length (when going file1 -> DB -> file2)?
Not sure what is wrong, however you could verify, without using Word, whether your file remains identical when going from file to database and back to file.
And why is it you use an explicit Open() and Read(), you could do a File.ReadAllBytes() exactly the same as in your WriteAllBytes().
|
|
|
|
|
Luc,
I know that this is probably not the proper way to handle this, but it does work. I set the open and repair to true on the open document. Thanks for your help!
Dim conn = New SqlConnection(My.Settings.Maintenance_ManagementSQLConnectionString)
Dim EQ As String = Me.Monsanto_Equip_NoTextBox.Text.ToString
Dim AreaCMD As New SqlCommand()
Dim wordDoc As Byte()
AreaCMD.Connection = conn
AreaCMD.CommandText = "SELECT LOTO FROM [tower]where [monsanto equip no] = '" & EQ & "'"
conn.Open()
wordDoc = AreaCMD.ExecuteScalar()
File.WriteAllBytes("C:\Temp\WordDoc.docx", wordDoc)
Dim appWord As New Word.Application
Dim docWord As New Word.Document
docWord = appWord.Documents.Open("C:\Temp\WordDoc.docx", , True, , , , , , , , , , True, , , )
appWord.Visible = True
|
|
|
|
|