|
You're not explaining your problem very well.
Are you saying that you want the font the text in the RTB is displayed in to resize itself so that it looks the same and fills the same area of the RTB the form is resized??
|
|
|
|
|
Yes something like that, i want the text inside the RTB to adjust automatically as the form get resize not the font size. (this form resize means manual resizing by mouse), i.e. i want the word inside the RTB to wrap automatically (like word wraping features)
|
|
|
|
|
The RTB won't do that. You'd have to write your own version of the control and it won't be easy.
The problem is that as your custom drawing your RTB, you have to measure a string in a font size and see how big the resulting bitmap image would be. If it's not big enough, or small enough, you have to create a new Font object to test and call MeasureString again, until you achieve the fit you want.
This is complicated by the fact that you still want WordWrap to work...
Oh, and the RTB doesn't consider one line of text on screen a single line. A single line of text wraps and keeps wrapping until a line break is hit. So, how many lines of text on screen are in that string?? See the problem??
|
|
|
|
|
I am writing a simple mouse/keyboard global logger. This part is the Mouse event class that uses a LowLevelMouseHook to drive events. I am getting a CallbackOnCollectedDelegate was detected run-time error that I cannot figure out. I am having trouble even trying to determine where the error is happening.
Any suggestions or clues would be welcomed.
Namespace nsMouseHook
Public Delegate Function LowLevelMouseHookProc(ByVal nCode As Integer, ByVal wParam As UInteger, ByRef lParam As MSLLHOOKSTRUCT) As Integer
Public Structure MSLLHOOKSTRUCT
Public pt As API_POINT
Public mouseData As UInteger
Public flags As UInteger
Public time As UInteger
Public dwExtraInfo As IntPtr
End Structure
Public Structure API_POINT
Public x As Integer
Public y As Integer
End Structure
End Namespace
Public Class GlobalMouseHook
Implements IDisposable
Private hhook As IntPtr = IntPtr.Zero
Private disposedValue As Boolean = False ' To detect redundant calls
Public Event MouseDown As MouseEventHandler
Public Event MouseUp As MouseEventHandler
Public Event MouseMove As MouseEventHandler
Private Const WM_MOUSEMOVE As UInteger = &H200
Private Const WM_LBUTTONDOWN As UInteger = &H201
Private Const WM_LBUTTONUP As UInteger = &H202
Private Const WM_MBUTTONDOWN As UInteger = &H207
Private Const WM_MBUTTONUP As UInteger = &H208
Private Const WM_RBUTTONDOWN As UInteger = &H204
Private Const WM_RBUTTONUP As UInteger = &H205
Private Const WH_MOUSE_LL As Integer = 14
Private Declare Auto Function LoadLibrary Lib "kernel32" (ByVal lpFileName As String) As IntPtr
Private Declare Auto Function SetWindowsHookEx Lib "user32.dll" (ByVal idHook As Integer, ByVal lpfn As nsMouseHook.LowLevelMouseHookProc, ByVal hInstance As IntPtr, ByVal dwThreadId As UInteger) As IntPtr
Private Declare Function CallNextHookEx Lib "user32" (ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As UInteger, ByRef lParam As nsMouseHook.MSLLHOOKSTRUCT) As Integer
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hhk As IntPtr) As Boolean
Public Sub New()
MouseHook()
GC.KeepAlive(Me)
End Sub
Private Sub MouseHook()
Dim hInstance As IntPtr = LoadLibrary("User32")
hhook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf Me.MouseHookProc, hInstance, 0) ' AddressOf Me.HookProc,
End Sub
Private Sub MouseUnhook()
UnhookWindowsHookEx(hhook)
End Sub
Private Function MouseHookProc(ByVal nCode As Integer, ByVal wParam As UInteger, ByRef lParam As nsMouseHook.MSLLHOOKSTRUCT) As Integer
If nCode >= 0 Then
Select Case wParam
Case WM_LBUTTONDOWN
RaiseEvent MouseDown(Me, New MouseEventArgs(MouseButtons.Left, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_RBUTTONDOWN
RaiseEvent MouseDown(Me, New MouseEventArgs(MouseButtons.Right, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_MBUTTONDOWN
RaiseEvent MouseDown(Me, New MouseEventArgs(MouseButtons.Middle, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_LBUTTONUP
RaiseEvent MouseUp(Me, New MouseEventArgs(MouseButtons.Left, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_RBUTTONUP
RaiseEvent MouseUp(Me, New MouseEventArgs(MouseButtons.Right, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_MBUTTONUP
RaiseEvent MouseUp(Me, New MouseEventArgs(MouseButtons.Middle, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_MOUSEMOVE
RaiseEvent MouseMove(Me, New MouseEventArgs(WM_MOUSEMOVE, 0, lParam.pt.x, lParam.pt.y, 0))
Case Else
Console.WriteLine(wParam)
End Select
End If
Return CallNextHookEx(hhook, nCode, wParam, lParam)
End Function
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
' TODO: free other state (managed objects).
End If
MouseUnhook()
End If
Me.disposedValue = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
GC.SuppressFinalize(Me)
Dispose(True)
End Sub
End Class
Option Strict On
Option Explicit On
Option Infer Off
Imports System.Runtime.InteropServices
Imports System.IO
Public Class MainForm
Private intTimeOfLastEvent As Double = 0 ' Time of the last recorded event
Private intTimeRecording As Double = 0 ' Recording time elaspesd
Private intTimePlaying As Double = 0 ' Timer value for playback
Private WithEvents gmh As GlobalMouseHook
Public Sub New()
InitializeComponent()
End Sub
' Form overrides dispose to clean up the component list.
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Catch ex As Exception
Finally
MyBase.Dispose(disposing)
End Try
End Sub
Private Sub MainForm_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
If gmh IsNot Nothing Then gmh.Dispose()
End Sub
''' <summary>Called when recording is started</summary>
''' <remarks></remarks>
Private Sub startRecording()
butPlay.Enabled = False
tRecordTime.Start()
bolRecording = True
gmh = New GlobalMouseHook
End Sub
''' <summary>Called when recording is stopped</summary>
''' <remarks></remarks>
Private Sub stopRecording()
tRecordTime.Stop()
bolRecording = False
gmh.Dispose()
End Sub
Private Sub gmh_MouseClickDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gmh.MouseDown
lbLog.Items.Add(String.Format("Time:{0}", (intTimeRecording - intTimeOfLastEvent) / 1000))
lbLog.Items.Add(String.Format("Mouse Click Down:{0}" & vbTab & "X:{1}" & vbTab & "Y:{2}", e.Button, e.X, e.Y))
lbLog.SelectedIndex = lbLog.Items.Count - 1
intTimeOfLastEvent = intTimeRecording
End Sub
Private Sub gmh_MouseClickUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gmh.MouseUp
lbLog.Items.Add(String.Format("Time:{0}", (intTimeRecording - intTimeOfLastEvent) / 1000))
lbLog.Items.Add(String.Format("Mouse Click Up:{0}" & vbTab & "X:{1}" & vbTab & "Y:{2}", e.Button, e.X, e.Y))
intTimeOfLastEvent = intTimeRecording
lbLog.SelectedIndex = lbLog.Items.Count - 1
End Sub
Private Sub gmh_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gmh.MouseMove
lblMousePosition.Text = e.X & ", " & e.Y
lbLog.Items.Add("Move")
lbLog.SelectedIndex = lbLog.Items.Count - 1
End Sub
Private Sub butRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butRecord.Click
If butRecord.Text = "Record" Then
butRecord.Text = "Stop Recording"
startRecording()
ElseIf butRecord.Text = "Stop Recording" Then
butRecord.Text = "Record"
stopRecording()
End If
End Sub
Private Sub tRunTime_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tRecordTime.Tick
intTimeRecording += tRecordTime.Interval
lblRecordTime.Text = (intTimeRecording / 1000).ToString("###.##")
lblRecordTime.Text = String.Format("Record Time:{0:###.##}", (intTimeRecording / 1000))
End Sub
Private Sub butExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butExit.Click, ExitToolStripMenuItem.Click
Me.Close()
End Sub
End Class
|
|
|
|
|
Hello Experts,
I am learning to make a font combobox and tried the following code, but how to add this combobox to the vb.net toolstrip. I am using vb.net 2005 Please help.
Imports System.Drawing
Public Class FontClass
Inherits ComboBox
Dim wait As Boolean
Public Sub New()
Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
Me.DropDownStyle = ComboBoxStyle.DropDownList
Me.Text = ""
Dim ff As FontFamily
Dim fc As New FontConverter
For Each ff In FontFamily.Families
Dim comboitem As New ComboBoxItem
If ff.IsStyleAvailable(FontStyle.Regular) Then
comboitem.Text = ff.Name
comboitem.Font = fc.ConvertFromString(ff.Name)
Me.Items.Add(comboitem)
End If
Next
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
e.DrawBackground()
e.DrawFocusRectangle()
Dim item As New ComboBoxItem
Dim bounds As New Rectangle
bounds = e.Bounds
Try
item = Me.Items(e.Index)
e.Graphics.DrawString(item.Text, item.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
Catch ex As Exception
If (e.Index <> -1) Then
e.Graphics.DrawString((e.Index).ToString(), e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
Else
e.Graphics.DrawString(Text, e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
End If
End Try
MyBase.OnDrawItem(e)
End Sub
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
wait = False
MyBase.OnMouseLeave(e)
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
wait = False
MyBase.OnMouseUp(e)
End Sub
Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
Try
If wait = False Then
Dim fc As New FontConverter
Me.Font = fc.ConvertFromString(Me.Text)
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
End Class
Public Class ComboBoxItem
Private ctext As String
Private cSelFont As Font
Property Text() As String
Get
Return ctext
End Get
Set(ByVal Value As String)
ctext = Value
End Set
End Property
Property Font() As Font
Get
Return cSelFont
End Get
Set(ByVal Value As Font)
cSelFont = Value
End Set
End Property
Public Overrides Function ToString() As String
Return ctext
End Function
End Class
Thanks in advance.
|
|
|
|
|
Have you thought of changing the "Inherit ComboBox" to "Inherit ToolStripComboBox"??
Then you might be able to drop your new Combo on the toolstrip.
|
|
|
|
|
Yes Dear I tried Inherits Toolstripcombobox but it say
DrawMode' is not a member of 'WindowsApplication1.FontClass'
|
|
|
|
|
OK, this was a bit harder than expected.
Basically, you have to use ToolStripControlHost[^] and wrap your custom combo (put the original Inherits line back in!). Then you can create an instance of the wrapped combo and add it to the ToolStrip.
You will NOT be able to use the designed to create the control on the form unless you tag your control with the ToolStripItemDesignerAvailability attribute.
I highly recommend reading the links I gave you, several times, and create a test project before you go screwing around in your real project. The concepts are a bit confusing.
|
|
|
|
|
Thanks Dave Kreskowiak,
I used ToolstripControlHost but dont understand how to use ToolStripItemDesignerAvailability attribute.
|
|
|
|
|
You put it just above your Public Class xxx line for you ToolStrip wrapper class. Something like:
<ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)> _
Public Class ToolStripCustomCombo
Inherits ToolStripControlHost
Public Sub New()
MyBase.New(New CustomCombo)
End Sub
End Class
|
|
|
|
|
 Thanks Dave,
It worked, below is my code:
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
<ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)> _
Public Class ToolStripmyFontCombo
Inherits ToolStripControlHost
Public Sub New()
MyBase.New(New FontClass)
End Sub
End Class
Public Class FontClass
Inherits ComboBox
Dim wait As Boolean
Public Sub New()
Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
Me.DropDownStyle = ComboBoxStyle.DropDownList
Me.Text = ""
Dim ff As FontFamily
Dim fc As New FontConverter
For Each ff In FontFamily.Families
Dim comboitem As New ComboBoxItem
If ff.IsStyleAvailable(FontStyle.Regular) Then
comboitem.Text = ff.Name
comboitem.Font = fc.ConvertFromString(ff.Name)
Me.Items.Add(comboitem)
End If
Next
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
e.DrawBackground()
e.DrawFocusRectangle()
Dim item As New ComboBoxItem
Dim bounds As New Rectangle
bounds = e.Bounds
Try
item = Me.Items(e.Index)
e.Graphics.DrawString(item.Text, item.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
Catch ex As Exception
If (e.Index <> -1) Then
e.Graphics.DrawString((e.Index).ToString(), e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
Else
e.Graphics.DrawString(Text, e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
End If
End Try
MyBase.OnDrawItem(e)
End Sub
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
wait = False
MyBase.OnMouseLeave(e)
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
wait = False
MyBase.OnMouseUp(e)
End Sub
Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
Try
If wait = False Then
Dim fc As New FontConverter
Me.Font = fc.ConvertFromString(Me.Text)
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
End Class
Public Class ComboBoxItem
Private ctext As String
Private cSelFont As Font
Property Text() As String
Get
Return ctext
End Get
Set(ByVal Value As String)
ctext = Value
End Set
End Property
Property Font() As Font
Get
Return cSelFont
End Get
Set(ByVal Value As Font)
cSelFont = Value
End Set
End Property
Public Overrides Function ToString() As String
Return ctext
End Function
End Class
But it gives me a warning:
Warning 1 Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found. 0 0
|
|
|
|
|
Hello,
I connected two computers in LAN 1st having IP 192.168.1.1 and 2nd having IP 192.168.1.2 and i am having sql server management studio express 2005 installed on 1st computer now when i run exe from 192.168.1.2 it throughs an error like.
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
where as it runs perfetly on 1st computer.
my conection string is
Public DBConn As ADODB.Connection
DBConn.ConnectionString = "Provider=MSDATASHAPE; Data Provider=SQLOLEDB.1;Data Source=TOSHIBA\SQLEXPRESS; Initial Catalog=" & App.Path & "\AVON_AIR_Data.mdf; User ID=sa; Password=; Integrated Security=SSPI; Persist Security Info=False;"
DBConn.Open DBConn.ConnectionString
Please suggest
Thank you.
|
|
|
|
|
This is VB forum, please post this question in the Database forum.
|
|
|
|
|
It'll be logging in on your first computer using Windows Authentication. Has the sa-account been enabled? Does the second PC have the correct password?
Bastard Programmer from Hell
|
|
|
|
|
You cannot use a database file on the local machine when connecting to a remote SQL Server instance.
You have to switch to a non-user-instance config string and permanently attach the database file on the remote machine to the SQL Server instance on the remote machine. This is easiesst done using the SQL Server Management tool. Then you can change the Initial Catalog option in your connection string to the database name you assign on the SQL Server.
If you're going to be using Integrated Security, do not supply a username and password. If you have to supply a username and password, do not use Integrated Security. The two options are mutually exclusive.
|
|
|
|
|
Hello,
I changed my connection string to
DBConn.ConnectionString = "Provider=SQLNCLI;AttachDBFileName=" & App.Path & "\newdb.mdf;Database=newdb;User Instance=true;Trusted_connection=Yes;"
but it gives me run time error like
Invalid connection string attribute..
Can you please suggest which attribute is invalid.
Thank You.
modified on Sunday, July 31, 2011 12:28 PM
|
|
|
|
|
How many times have you asked this question?
You don't have a clue what you're doing, do you?
You haven't understood any of the things I said in my other post and know nothing of what's in the connection string. Your "second" attempt you posted contains none of the fixes I told you about and you're still trying to attach a remote instance of SQL Server to a local file, which will not work.
http://www.connectionstrings.com[^]
|
|
|
|
|
|
thatraja wrote: Looks like you have posted this question multiple times
And you still keep answering him each time?
|
|
|
|
|
No, only 2nd time
|
|
|
|
|
Can I use MS Windows theme as GUI in my project?
|
|
|
|
|
Why would you want to?
Better to have your own gui, much more professional.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Hi,
I need to plot a graph(bar charts) on windows form using values from a closed excel sheet .. tried but unable to do so .. can someone plz help me with a small example of how to implement using Zedgraph or any other suitable package ..
Regards...
Gauti..
|
|
|
|
|
|
|