|
Hi, I have a treeview control on a vb form and have subclassed the form. I want to be able to highlight/select an item when the mouse is moved over a treeview item without giving the treeview the input focus. I've trapped the WM_NOTIFY message and checking for the NM_SETCURSOR code. I like to know how I can get the mouse position from the NMMOUSE structure and sending a TVM_SELECTITEM to the treeview to select the item. I've output what x & y is from the NMMOUSE but x seems to always be zero. Can dwHitInfo be used somehow?
Friend Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim notify_header As NMHDR
Dim mouse_info As NMMOUSE
Dim tvhti As TVHITTESTINFO
Dim Ret As Long
Select Case uMsg
Case WM_NOTIFY
'Copy the WM_NOTIFY details into the notifiy_header structure.
CopyMem notify_header, ByVal lParam, LenB(notify_header)
If notify_header.hwndFrom = m_Frm.tvControl.hWnd Then
If notify_header.code = NM_SETCURSOR Then
CopyMem mouse_info, ByVal lParam, LenB(mouse_info)
Debug.Print "mouse moving x=" & mouse_info.pt.x & " y=" & mouse_info.pt.y
'tvhti.pt.x = mouse_info.pt.x
'tvhti.pt.y = mouse_info.pt.y
Ret = SendMessage(m_Frm.tvControl.hWnd, TVM_HITTEST, 0&, tvhti)
If Ret > 0 Then
Ret = SendMessage(m_Frm.tvControl.hWnd, TVM_SELECTITEM, TVGN_CARET, tvhti.hItem)
End If
End If
End If
End Select
WndProc = CallWindowProc(m_OrigWndProc, hWnd, uMsg, wParam, lParam)
End Function
|
|
|
|
|
lee23 wrote: I want to be able to highlight/select an item when the mouse is moved over a treeview item without giving the treeview the input focus.
That sounds awfully messy and inconsistent with how user expect the TreeView controls to work. But to clarify, you want to select TreeView items just by moving the mouse over them?? Not by clicking on them??
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi Dave, yes that's correct.
|
|
|
|
|
OK - Yikes. That's not good. You'd have to leave the mouse on the node you want and not move it at all. I'm one of those people who clicks on something and then reads something else with the mouse pointer following where I'm looking. In order to keep the currently selected item in the TreeView picked, you'd have to slide the mouse off to the left or right of the TreeView while maintaining the mouse pointer on the same line as the item selected.
Are you sure this is what you want?
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
what i'm trying to create is a combobox but instead of dropping down a listbox, it drops down a treeview. So, i have a textbox and button on a usercontrol. when the button is clicked it shows/hides the treeview that's on a vb form. So, I want to replicate the behaviour of a standard combobox of style dropdown where when you drop down the list the input focus remains on the textbox but when u move the mouse over the listbox, the item the mouse is on is highlighted.
|
|
|
|
|
Ok. That explains a lot.
You can highlight the item that the mouse is rolling over, but you still have to click on it to select it. Selection by rollover is notoriously difficult to control because the user has to know that the mouse must move off the control only to the left or right to maintain the selection.
I'm really short on time right now, so there will be more to follow....
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
This is the code i am using to try and send an email. I am using vb.net 2003
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click<br />
<br />
If txtto.Text = "" Then<br />
MsgBox("Please enter the address to send this message, E.g, Someone@someone.com")<br />
End If<br />
If txtto.Text <> "" Then<br />
Dim email As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage<br />
email.To = txtto.Text<br />
email.Cc = txtcc.Text<br />
email.Bcc = txtbcc.Text<br />
email.Subject = txtsubject.Text<br />
email.From = "someone@someone.com"<br />
email.Body = txtmessage.Text<br />
Dim sAttach As String = txtattach.Text<br />
If txtattach.Text <> "" Then<br />
Dim delim As Char = ","<br />
Dim sSubstr As String<br />
For Each sSubstr In sAttach.Split(delim)<br />
Dim myAttachment As MailAttachment = New MailAttachment(sSubstr)<br />
<br />
email.Attachments.Add(myAttachment)<br />
Next<br />
End If<br />
System.Web.Mail.SmtpMail.SmtpServer = ""<br />
System.Web.Mail.SmtpMail.Send(email) Error here
End If<br />
End Sub
Error I get:
An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll
Additional information: Could not access 'CDO.Message' object.
|
|
|
|
|
There's lots of info out on the web about this. All you have to do is Google "tourbleshooting CDO.Message[^]".
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Try this code.
Hope this will help u.
Public Function OpenEmail(ByVal EmailAddress As String) ', Optional ByVal Subject As String = "", Optional ByVal Body As String = "") As Boolean
Dim bAns As Boolean = True
Dim sParams As String
sParams = EmailAddress
If LCase(Strings.Left(sParams, 7)) <> "mailto:" Then sParams = "mailto:" & sParams
'If Subject <> "" Then sParams = sParams & _
' "?subject=" & Subject
'If Body <> "" Then
' sParams = sParams & IIf(Subject = "", "?", "&")
' sParams = sParams & "body=" & Body
'End If
Try
System.Diagnostics.Process.Start(sParams)
Catch
bAns = False
End Try
Return bAns
End Function
|
|
|
|
|
A***** wrote: System.Web.Mail.SmtpMail.SmtpServer = ""
Sorry, I missed this line before. You MUST specify an SMTP server to use, either by IP address or by a valid DNS name. You cannot send mail without one.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thanks for the help, amaneet and dave.
|
|
|
|
|
Alright, basically I am trying to create a function that does the following:
The user has a rank
The possible ranks a user can have are stored in an array ("RankTree()")
The Public Sub in the class is called Promote(Byval Position As String)
My problem is that I'm trying to make the sub find the index of the user's rank in RankTree, then move foreward one index, and set the user's Position (Dude.Position) to the next rank in the array.
How do I go about doing this?
|
|
|
|
|
Diagathon wrote: The possible ranks a user can have are stored in an array ("RankTree()")
Why is this an Array? Why couldn't you use an Enum?
Diagathon wrote: The Public Sub in the class is called Promote(Byval Position As String)
My problem is that I'm trying to make the sub find the index of the user's rank in RankTree
All you have to do is enumerate (For i=0 to ...) the string (I'm assuming they're strings!) in the array and check the current Position to each one in the array. When you find it, I contains the index. All you have to do is increment it.
This problem would probably be better suited for an Enum...
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I'll suggest using a LinkedList. Here is an example:
First define a class to hold your object.
Public Class Dude
Public _Name As String
Public _Position As Integer
Public Sub New(ByVal Name As String, ByVal Position As Integer)
_Name = Name
_Position = Position
End Sub
End Class
Then in your main app, define the LinkedList to hold these individual objects.
Dim MyDudes as New LinkList(Of Dude)
You can add items to this several ways:
MyDudes.AddFirst(NewDude)
MyDudes.AddAfter(PreviousDude,NewDude)
MyDudes.AddBefore(BeforeDude,NewDude)
MyDudes.AddLast(NewDude)
There are Find Methods, and Remove methods that can easily help with what you need.
Hope this helps!
~ CodeDoctor ~
|
|
|
|
|
Hi,
I am new to VB.net and am writing my first little application that will print a series of images from a data grid to a printer (in this a PDF driver).
If it does one page then it works, but I want it to print onto seperate pages, then it either prints the first page spot on, but then nothing else, or just prints the next set of images over the previous ones. I think I have tried all version of HasMorePages but I may just have it in the wrong place....
Any help would be appreciated....
Thanks
Jamie
Private Sub Test_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Test.Click
Try
AddHandler PrintGraphicControl.PrintPage, AddressOf Me.GraphicPrint1
PrintGraphicControl.Print()
Catch ex As Exception
MsgBox("Test Error" & ex.Message)
End Try
End Sub
Private Sub GraphicPrint1(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim i As Integer
Dim rCnt As Integer 'row count
Dim cLeft = e.MarginBounds.Left
Dim cTop = e.MarginBounds.Top
Dim pLength = e.MarginBounds.Bottom - e.MarginBounds.Top
Dim iName As String
For i = 1 To DataGridView1.RowCount
rCnt = rCnt + 1
Next
For i = 1 To rCnt
DataGridView1.CurrentCell = DataGridView1(curColumn, i - 1)
iName = imgPath & (DataGridView1.CurrentCell.Value) & ".jpg"
Try
Dim rDest As New RectangleF(cLeft, cTop, 0, 0)
Dim printFont As Font = New Font("Arial", 10, FontStyle.Regular)
If Image.FromFile(iName).Width < e.MarginBounds.Width Then
'-- Set to bitmap size if bitmap is smaller than paper
rDest.Width = Image.FromFile(iName).Width
rDest.Height = Image.FromFile(iName).Height
Else
'-- Set to paper size if bitmap is larger than paper
'-- Scale height to retain proportions
rDest.Width = e.MarginBounds.Width
rDest.Height = CType(rDest.Width * (Image.FromFile(iName).Height / Image.FromFile(iName).Width), Single)
End If
If pLength < cTop + rDest.Height + (3 * printFont.GetHeight(e.Graphics)) Then
cLeft = e.MarginBounds.Left
cTop = e.MarginBounds.Top
e.HasMorePages = True
Else
e.HasMorePages = False
End If
e.Graphics.DrawImage(Image.FromFile(iName), rDest, Image.FromFile(iName).GetBounds(GraphicsUnit.Pixel), GraphicsUnit.Pixel)
'-- Draw timestamp
e.Graphics.DrawString(Now.ToString, printFont, Brushes.Black, rDest.Left, rDest.Top + rDest.Height + printFont.GetHeight(e.Graphics))
cTop = cTop + rDest.Height + (3 * printFont.GetHeight(e.Graphics))
Catch
End Try
Next i
End Sub
|
|
|
|
|
From what I can see, or more accurately what I can NOT see, in you're code is any support for getting the page number that is currently being printed and using that in some way as an index into what you're supposed to be printing.
What your GraphicPrint1 handler is called, it's job is to print the single page that is being worked on. Nowhere in your code are you tracking what is on the current page, what you have printed, or what you have remaining to be printed.
In the example that I'm assuming you used to model this code from, in the PrintDocument.PrintPage event documentation on MSDN, notice that the StreamReader at the top of the code (declared in class scope) is what is tracking what was printed and what remains to be printed:
Public Class PrintingExample
Inherits System.Windows.Forms.Form
Private streamToPrint As StreamReader
...
Private Sub printButton_Click(sender As Object, e As EventArgs)
Try
streamToPrint = New StreamReader("C:\My Documents\MyFile.txt")
...
Finally
streamToPrint.Close()
End Try
End Sub
Private Sub pd_PrintPage(sender As Object, ex As PrintPageEventArgs)
Dim line As String = Nothing
...
line = streamToPrint.ReadLine()
...
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub
OK. So how does the PrintPage handler know when there is no more text to print? The streamToPrint is defined in class scope, so it doesn't lose it's place inside the PrintPage handler when everything else in there goes out of scope and is destroyed. That StreamReader is what is keeping track of what has been printed and what still needs to be printed. Notice that the StreamReader is created and destroyed in the Button_Click event, not in the PrintPage event!
Your code has to do something similar. It has to have class scoped variable that keep track of what has been printed or what still needs to be printed, like an index number into an array or collection that your GraphicPrint event has to advance to the next image and check to see if it still has more images to go.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Many thanks Dave... I think I misunderstood quite how it was supposed to work!
Thanks again!
|
|
|
|
|
Yeah, I've found that describing how Printing and DataGrid's work is a bit of large undertaking when someone doesn't know the basics of programming or OOP. You, on the other hand, seemed to have a good enough grip on them, which makes the process a whole lot easier to describe!
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I'm quite new to programming and VB.NET, so Idon't know if this is really obvious.
I ran my Rich Text Editor (using Telerik R.A.D. RibbonBar and your own ExtendedRichTextBox), and I got the following error:
An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
Stack trace:
at WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190<br />
at WindowsApplication1.My.MyProject.MyForms.get_frmMain()<br />
at WindowsApplication1.My.MyApplication.OnCreateMainForm() in C:\Documents and Settings\lucas\My Documents\Visual Studio 2005\Projects\LucasToolsEditor\My Project\Application.Designer.vb:line 35<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)<br />
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81<br />
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)<br />
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br />
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br />
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br />
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br />
at System.Threading.ThreadHelper.ThreadStart()
Thanks.
|
|
|
|
|
Sorry I did not mention this, but my RibbonBar has disappeared. Kind of. When I click on its area, it shows up in the properties window, but it is just blankon the form.
Sorry.
|
|
|
|
|
You're probably going to have to remove the RibbonBar from your project, then go through the code files for your form and remove all mention of the RibbonBar. This should let you reopen the form in the Designer. If it does, then you can try to readd the RibbonBar and resetup the properties you had setup for it.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thanks, I'll just try that now.
|
|
|
|
|
Hi,
I want to access database which is kept on website in database folder.
Anybody could help me please? How to connect this database? What should be
connectionstring for it with detail code? i am developing it in Vb.net 2005 with MS Access database.
I am beginer for vb.net.
If possible please send me example.
Database path is like: http://XXX.XXX.XXX.XXX/abc/database
How to write the connection string; Also the database is password protected;
Kiran Sajanikar
-- modified at 9:14 Wednesday 11th April, 2007
|
|
|
|
|
You can't do that unless you want to open up a HUGE security hole. Most web sites, as I hope yours as well, will not allow you to write to folders over HTTP. You need to be able to open the database with both Read AND Write permissions to use it.
You can, however, still use the database. But, you have to write a web service, which runs on HTTP, to do all the database work for your application.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thanx for your reply,
But as I told you that I am beginer to vb.net; so I am bit confused. Now how should i proceed to solve my problem. Give me some hints so I can strat my project.
Kiran Sajanikar
|
|
|
|
|