15,894,343 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by 10071962 (Top 40 by date)
10071962
3 days ago
View
You're right, sorry, I'll keep looking... Thanks!
10071962
3 days ago
View
First of all, I thank you for the time you spent and the effort you made, I attach the new derived class, completely empty, that I created to test your code, avoiding possible interference, and I inserted it in a form that is also empty , the problem is that it doesn't work for me, the hand appears randomly in the control area even though the mouse coordinates are correct and the image inserted correctly in the "imageLocations", I don't want to have done something wrong. I also tried with the Windows API (IRichEditOle Interface) but it doesn't work, yet for a relatively simple thing there is no direct call to the RichtextBox which is unnerving. Thanks again and happy Sunday. NOTE: I attach the class as an answer, I can't do it here, maybe the text is too long.
10071962
3 days ago
View
Deleted
First of all, I thank you for the time you spent and the effort you made, I attach the new derived class, completely empty, that I created to test your code, avoiding possible interference, and I inserted it in a form that is also empty , the problem is that it doesn't work for me, the hand appears randomly in the control area even though the mouse coordinates are correct and the image inserted correctly in the "imageLocations", I don't want to have done something wrong. I also tried with the Windows API (IRichEditOle Interface) but it doesn't work, yet for a relatively simple thing there is no direct call to the RichtextBox which is unnerving. Thanks again and happy Sunday.
Option Explicit On
Option Strict Off
Imports System.Windows
Public Class ExtendedRichTextBox : Inherits RichTextBox
Private imageLocations As List(Of Tuple(Of Integer, Integer))
Public Sub New()
MyBase.New()
imageLocations = New List(Of Tuple(Of Integer, Integer))
End Sub
'*****************************************************************************************
'*****************************************************************************************
Public Sub Me_InsertImage(ImagePath As String)
If Not System.IO.File.Exists(ImagePath) Then
Dim parentForm As Form = Me.FindForm()
Forms.MessageBox.Show(parentForm, "Il percorso dell'immagine specificato non esiste.", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
Dim img As Image = Image.FromFile(ImagePath)
Forms.Clipboard.SetImage(img)
Me.Paste()
End Sub
'*****************************************************************************************
'*****************************************************************************************
Protected Overrides Sub OnTextChanged(e As EventArgs)
MyBase.OnTextChanged(e)
If Me.IsHandleCreated Then
FindImageLocations()
End If
End Sub
Private Function FindImageLocations() As Boolean
imageLocations.Clear()
Dim startTag As String = "{\pict"
Dim openBrace As Char = "{"c
Dim closeBrace As Char = "}"c
Dim braceCount As Integer
Dim currentPosition As Integer
Dim nextOpenBrace As Integer
Dim nextCloseBrace As Integer
Dim currentImageStart As Integer = Me.Rtf.IndexOf(startTag, 0)
If currentImageStart = -1 Then Return False
While currentImageStart <> -1
braceCount = 1
currentPosition = currentImageStart + startTag.Length
While braceCount <> 0
nextOpenBrace = Me.Rtf.IndexOf(openBrace, currentPosition)
nextCloseBrace = Me.Rtf.IndexOf(closeBrace, currentPosition)
If nextOpenBrace <> -1 Then
currentPosition = Math.Min(nextOpenBrace, nextCloseBrace)
Else
currentPosition = nextCloseBrace
End If
If Me.Rtf.Chars(currentPosition) = openBrace Then
braceCount += 1
ElseIf Me.Rtf.Chars(currentPosition) = closeBrace Then
braceCount -= 1
Else
Throw New Exception("Unexpected error")
End If
currentPosition += 1
End While
imageLocations.Add(Tuple.Create(currentImageStart, currentPosition))
My.Forms.Form_Di_Test_09_ExtendedRichTextBox.ToolStripStatusLabel_Start.Text = "Start, " & currentImageStart.ToString()
My.Forms.Form_Di_Test_09_ExtendedRichTextBox.ToolStripStatusLabel_End.Text = "End, " & currentPosition.ToString()
currentImageStart = Me.Rtf.IndexOf(startTag, currentPosition)
End While
Return True
End Function
Prot
10071962
3 days ago
View
Deleted
First of all, I thank you for the time you spent and the effort you made, I attach the new derived class, completely empty, that I created to test your code, avoiding possible interference, and I inserted it in a form that is also empty , the problem is that it doesn't work for me, the hand appears randomly in the control area even though the mouse coordinates are correct and the image inserted correctly in the "imageLocations", I don't want to have done something wrong. I also tried with the Windows API (IRichEditOle Interface) but it doesn't work, yet for a relatively simple thing there is no direct call to the RichtextBox which is unnerving. Thanks again and happy Sunday.
Option Explicit On
Option Strict Off
Imports System.Windows
Public Class ExtendedRichTextBox : Inherits RichTextBox
Private imageLocations As List(Of Tuple(Of Integer, Integer))
Public Sub New()
MyBase.New()
imageLocations = New List(Of Tuple(Of Integer, Integer))
End Sub
'*****************************************************************************************
'*****************************************************************************************
Public Sub Me_InsertImage(ImagePath As String)
If Not System.IO.File.Exists(ImagePath) Then
Dim parentForm As Form = Me.FindForm()
Forms.MessageBox.Show(parentForm, "Il percorso dell'immagine specificato non esiste.", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
Dim img As Image = Image.FromFile(ImagePath)
Forms.Clipboard.SetImage(img)
Me.Paste()
End Sub
'*****************************************************************************************
'*****************************************************************************************
Protected Overrides Sub OnTextChanged(e As EventArgs)
MyBase.OnTextChanged(e)
If Me.IsHandleCreated Then
FindImageLocations()
End If
End Sub
Private Function FindImageLocations() As Boolean
imageLocations.Clear()
Dim startTag As String = "{\pict"
Dim openBrace As Char = "{"c
Dim closeBrace As Char = "}"c
Dim braceCount As Integer
Dim currentPosition As Integer
Dim nextOpenBrace As Integer
Dim nextCloseBrace As Integer
Dim currentImageStart As Integer = Me.Rtf.IndexOf(startTag, 0)
If currentImageStart = -1 Then Return False
While currentImageStart <> -1
braceCount = 1
currentPosition = currentImageStart + startTag.Length
While braceCount <> 0
nextOpenBrace = Me.Rtf.IndexOf(openBrace, currentPosition)
nextCloseBrace = Me.Rtf.IndexOf(closeBrace, currentPosition)
If nextOpenBrace <> -1 Then
currentPosition = Math.Min(nextOpenBrace, nextCloseBrace)
Else
currentPosition = nextCloseBrace
End If
If Me.Rtf.Chars(currentPosition) = openBrace Then
braceCount += 1
ElseIf Me.Rtf.Chars(currentPosition) = closeBrace Then
braceCount -= 1
Else
Throw New Exception("Unexpected error")
End If
currentPosition += 1
End While
imageLocations.Add(Tuple.Create(currentImageStart, currentPosition))
My.Forms.Form_Di_Test_09_ExtendedRichTextBox.ToolStripStatusLabel_Start.Text = "Start, " & currentImageStart.ToString()
My.Forms.Form_Di_Test_09_ExtendedRichTextBox.ToolStripStatusLabel_End.Text = "End, " & currentPosition.ToString()
currentImageStart = Me.Rtf.IndexOf(startTag, currentPosition)
End While
Return True
End Function
Prot
10071962
29-Apr-24 8:59am
View
Thank you, but I had tried, also replacing Dim imageIndex As Integer = text.IndexOf("\pict\wmetafile8"), the RTF code is "{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\ fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17\par
{\pict\wmetafile8\picw3386\pich3386\picwgoal1920\pichgoal1920
010009000003386000000000226000000000050000000b0200000000050000000c023a0d3a0d22" etc... The nice thing is that I created a new project, with an empty derived class but it doesn't want to know about it..
10071962
18-Apr-24 0:35am
View
Thanks for your time, I did some testing and from what I saw the only correct value when it doesn't throw an exception is clientAreaWidth. For the rest it gives me the usual memory pointer values (I learned). This is what I did, it's highlighted where it sometimes throws an exception. I use the function directly in the derived class and I don't want this to be the problem, but I tried in the form and the result changes little, i.e. the values seem lower. I didn't think it was so complicated to have a value that should be accessible by default.
Private Function GetSelectionMarginWidth() As Integer
Try
Dim margins As New RECT()
Dim lParam As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(margins))
SendMessage(Me.Handle, EM_GETMARGINS, IntPtr.Zero, lParam)
margins = Marshal.PtrToStructure(lParam, GetType(RECT))
Marshal.FreeHGlobal(lParam)
Dim leftMargin As Integer = margins.Left
Dim rightMargin As Integer = margins.Right
'*** exception ***
Dim clientAreaWidth As Integer = Me.Width - leftMargin - rightMargin
'*****************
Dim controlRect As New RECT()
Dim rectParam As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(controlRect))
SendMessage(Me.Handle, EM_GETRECT, 0, rectParam)
controlRect = Marshal.PtrToStructure(rectParam, GetType(RECT))
Marshal.FreeHGlobal(rectParam)
Dim controlWidth As Integer = controlRect.Right - controlRect.Left
Dim selectionBorderWidth As Integer = controlWidth - clientAreaWidth
Return selectionBorderWidth 'controlWidth - clientAreaWidth
Catch ex As Exception
Return 0
End Try
Return 0
End Function
10071962
17-Apr-24 11:59am
View
It doesn't work, it was referring to the GetSelectionMarginWidth function, from which I expected an integer value as the width of the selection border... Now if I may, is there a way to extract this blessed width of the selection border from these memory addresses or pointers? The method I posted below doesn't seem very professional to me. Sorry again for the Google English...
10071962
16-Apr-24 0:17am
View
Thank you for your help, but it doesn't work, debugging gives me meaningless values:
909586995
892612915
875574835
3211315
892940345
3145785
892679992
3604536
3407923
892940345
909586995
909586995
925905971
3145785
3538995
842609976
3276857
3735608
942880051
3276851
10071962
16-Apr-24 0:16am
View
True, it escaped me.
10071962
11-Feb-24 9:13am
View
The only solution I see is to import the project into vs2015, then create a routine that searches for all the properties involved in the layout and modifies the value. The only problem is that I don't trust the result (I don't remember all the changes made) and I should still check all the windows. This or rewrite everything from scratch. Thanks for your help
10071962
11-Feb-24 8:52am
View
I noticed that by importing the entire project from 2010 to 2015, the compiler adds 10 pixels in height and width, as you say for the Windows 10 style. The problem is that by doing so it modifies the entire layout added programmatically. Your suggestion would be fine for a few windows, but changing hundreds of them is equivalent to rewriting the project from scratch with net 4.5. Thank you for your suggestion.
10071962
10-Feb-24 8:35am
View
I forgot a detail to be more precise, the biggest difference is especially noticeable by setting FormBorderStyle.FixedToolWindow, the size is completely different.
10071962
10-Feb-24 8:16am
View
Thanks, I've read everything but I don't think it's a problem with "AutoScaleDimensions", or with "AutoScaleMode.Dpi", but I think it's a different management of the form by the compiler. The problem is not only in execution but above all during the creation of the form in a visual way. Even if you add an empty form, the size of the border and the height of the title bar of the form is 10 pixels greater than in vs2010 and this affects the imported forms which should be left pixel by pixel as they were. Or am I the one who doesn't understand...
10071962
5-Feb-24 12:02pm
View
Done, thanks. Installed version 2015...
10071962
5-Feb-24 12:01pm
View
It was the one I had available on disk to install and it supports "yield" with net 4.5, as soon as I tried it. It's fine for now, I just didn't understand how to install the offline guide. I use Windows 10. Good evening...
10071962
5-Feb-24 10:34am
View
Just installed Visual Studio 2015. Thanks
10071962
5-Feb-24 10:00am
View
Thank you, I'll do some tests and see if I can implement it, by points I mean the coordinates of a rectangle. Thanks again
10071962
5-Feb-24 5:54am
View
Monstrous work, congratulations. I was wondering if it could work the same if instead of passing integer values I pass strings or dots... Also how do you know the value of "enumerableobject" in advance? going back to my example:
public IEnumerable<range> GetRanges(string regexPattern)
{
var range = new Range(this);
range.SelectAll();
//
foreach (Range r in range.GetRanges(regexPattern, RegexOptions.None))
yield return r;
}
How would you pass it on to your class?
Thank you!
10071962
5-Feb-24 2:48am
View
Because up until now it has always been perfect for my uses...
10071962
5-Feb-24 2:37am
View
I know, it's not simple... This is why I need your help, I'm not that advanced, I tried but it's complicated...
10071962
5-Feb-24 2:36am
View
Thank you, but "Yield" is not supported by the 2010 version...
10071962
18-Jan-24 8:24am
View
Thank you very much!
10071962
17-Jan-24 0:39am
View
Deleted
Perfect! It also gives a simple explanation of the differences. As soon as I get to try it I'll update you. Thank you very much!
10071962
17-Jan-24 0:39am
View
Deleted
Perfect! It also gives a simple explanation of the differences. As soon as I get to try it I'll update you. Thank you very much!
10071962
17-Jan-24 0:39am
View
Perfect! It also gives a simple explanation of the differences. As soon as I get to try it I'll update you. Thank you very much!
10071962
16-Jan-24 2:33am
View
What do you think of this solution? It might work? I can't really try it yet.
Dim Buff() As Char = Text.ToCharArray
Dim c() As Char
Dim obj As Object = Buff
Dim gh As Runtime.InteropServices.GCHandle = Runtime.InteropServices.GCHandle.Alloc(obj, Runtime.InteropServices.GCHandleType.Pinned)
Dim ip As IntPtr = gh.AddrOfPinnedObject()
Runtime.InteropServices.Marshal.Copy(Buff, 0, ip, 4)
c = Buff
gh.Free()
See: "https://www.c-sharpcorner.com/forums/c-sharp-to-vb-net-conversion-byte-pointers-etc"
Thank you
10071962
16-Jan-24 0:29am
View
Thanks, I tried all your suggestions but without success; the closest one is "https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/strings/how-to-access-characters-in-strings" , but this isn't functional either. Dave Kreskowiak, I don't quite understand what you mean. Thank you all.
10071962
16-Jan-24 0:29am
View
Thanks, I tried all your suggestions but without success; the closest one is "https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/strings/how-to-access-characters-in-strings" , but this isn't functional either. Dave Kreskowiak, I don't quite understand what you mean. Thank you all.
10071962
16-Jan-24 0:29am
View
Thanks, I tried all your suggestions but without success; the closest one is "https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/strings/how-to-access-characters-in-strings" , but this isn't functional either. Dave Kreskowiak, I don't quite understand what you mean. Thank you all.
10071962
15-Jan-24 11:26am
View
Because having the source in VB I can modify it and integrate it into my project which is a cryptographic editor and I am interested in some functions of this library that you find here.
https://code.google.com/archive/p/alsing/downloads
10071962
14-Nov-23 3:57am
View
Thanks for the reply, I think my code isn't too much to blame, in fact to be careful I inserted an empty form, added a richtextbox with only ShowSelectionMargin = True as the changed property. The mouse cursor in the selection area does not appear at all, it remains IBeam regardless. As per this article: https://github.com/dotnet/winforms/issues/3063 there is a control bug. Unfortunately I'm not good enough to solve it.
10071962
12-Nov-23 11:50am
View
Yes, I had read it, but on the one hand it reiterates that it is a problem with the richtextbox, and on the other that my problem is another, I don't have flickering, but the wrong position, and strangely enough, this behavior disappears after a while. Too bad nothing can be done. BYE
10071962
12-Nov-23 11:11am
View
Certain. .ShowSelectionMargin = False
10071962
12-Nov-23 11:08am
View
I want to display text selection mouse (arrow right) like in word or notepad++. For some reason the richtextbox gives the option to set ShowSelectionMargin but then doesn't display the appropriate cursor.
10071962
12-Nov-23 11:04am
View
I set ShowSelectionMargin to false, but the problem is the same, the mouse goes out of the position you would expect. Thank you all the same.
10071962
12-Nov-23 10:06am
View
So, I stripped the class down to its bare bones, created a new project with a form and inserted the class. The problem is obvious, try writing something and then move to the text selection area. I wanted to attach the rar file but I don't know if it's possible and how to do it.
10071962
12-Nov-23 9:10am
View
I removed all references to the basic project, but the behavior is the same.
10071962
12-Nov-23 7:28am
View
As soon as I followed your advice, I inserted the complete class. Thank you
10071962
12-Nov-23 0:44am
View
For completeness, if I add this code, the position is perfect, but then obviously it "busts" when it starts working correctly again.
Dim New_Point = Me.PointToScreen(New Point(e.X, e.Y))
New_Point.X = New_Point.X - 10
New_Point.Y = New_Point.Y + 10
Cursor.Position = New_Point
10071962
12-Nov-23 0:24am
View
The problem is that the richtextbox at least in .Net 4 does not display the text selection cursor (rightward arrow). Must be a Bug since there is nothing in the derived class that can interfere, just the setting SelectionIndent = 10. Gerry Schmitz What should I undo? Furthermore, after inserting a few lines of text, the mouse behaves as expected.
Show More