|
Hey, do you have the new version? I would like to see it.
public class SysAdmin : Employee
{
public override void DoWork(IWorkItem workItem)
{
if (workItem.User.Type == UserType.NoLearn){
throw new NoIWillNotFixYourComputerException(new Luser(workItem.User));
}else{
base.DoWork(workItem);
}
}
}
|
|
|
|
|
Hello Brian,
if you debug the code you will find out that in ExtendedRichTextBox class in a definition of property SelectionFont2 in line 1540 there is a bug: the factor for calculating yHeight attribute of CHARFORMAT2 structure should be 20 not 14.4 (which currently is represented by variable AnInch).
Quick correction solves the case.
Michal Orlik
michael.orlik@wp.pl
|
|
|
|
|
Thanks Michael,
I was also looking for the bug. Thanks very much for sharing the solution.
Brian
brian at BCC
|
|
|
|
|
Hi Aleksei.
Hyperlinks that have spaces included do not work as expected. E.g. the hyperlink
file:\\c:\documents and settings\frank\somefile.txt. The text left of the first space is highlighted but the link does not work. Any ideas? (besides removing the spaces)
Cheers,
Frank
|
|
|
|
|
Hello.
Actually, this is an issue of the RichTextBox. Well, I found a solution.
Firstly, it's easier to use arbitrary links (like, click here, instead of file://somefile).
You sould add a function to the ExtendedRichTextBox, which will instert hyperlinks. Here is what I use:
internal void InsertHyperlink(string text, string address, Color linkColor)
{
if (address == null) return; if (address == "") return;
if (text == "") text = address;
string _val = "", _val2 = "";
string s = @"{\rtf1\ansi\ansicpg1251\deff0\deflang1049" +
Environment.NewLine + @"{\colortbl ;\red" + linkColor.R.ToString() + @"\green" + linkColor.G.ToString() + @"\blue" + linkColor.B.ToString() + ";}" +
Environment.NewLine + @"{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1 ";
string s1 = "\\pard \\protect {\\field{\\*\\fldinst{HYPERLINK \"";
string s2 = "\" }}{\\fldrslt{\\cf1\\ul ";
string s3 = "}}}\\cf0\\ulnone\\f0 ";
_val2 = "\\uc0 ";
for (int i = 0; i < address.Length; i++)
{
_val2 += "\\u" + ((short)address[i]).ToString() + " ";
}
_val = s + s1 + _val2 + s2;
_val2 = "\\uc0 ";
for (int y = 0; y < text.Length; y++)
{
_val2 += "\\u" + ((short)text[y]).ToString() + " ";
}
_val += _val2 + s3 + Environment.NewLine + "\\protect0 " + Environment.NewLine + "}";
this.SelectedRtf = _val;
}
It's not perfect, but working. It uses MS Word style hyperlinks (it uses HYPERLINK keyword defined inside field). After adding the code above provide the link text (caption), address (this is the path to your file) and optionally the color of the link.
One more thing. On my computer there was a problem. Method above worked only if there was some text after the link. . It was somehow unexpected. Fortunatly I found the solution. You have to handle the LinkClicked event in the WndProc in the following way:
if (m.Msg == 8270)
{
NativeMethods.ENLINK lParam;
lParam = m.GetLParam(typeof(NativeMethods.ENLINK)) as NativeMethods.ENLINK;
if (lParam != null)
{
if (lParam.msg == 513)
{
string str = this.CharRangeToString(lParam.charrange);
if (!string.IsNullOrEmpty(str))
{
m.Result = (IntPtr)1;
OnLinkClicked(new LinkClickedEventArgs(str));
}
else base.WndProc(ref m);
}
else base.WndProc(ref m);
}
else base.WndProc(ref m);
}
It happens that way: user clicks the link, we handle it, than we get its address (this should be you filename) and convert it into a string. After that we rise the OnLinkClicked event and passing the address to it. All you need to do is just to decide what to do it LinkClicked proc.
Fortunately, definition for ENLINK, TEXTRANGE, NMHDR and CHARRANGE you can find in the MSDN. And here is the definitions for CharRangeToString function:
private class CharBuffer
{
internal char[] buffer;
internal int offset;
internal CharBuffer(int size)
{
if (size > 8196 || size < 0)
{
this.buffer = new char[0];
return;
}
try
{
this.buffer = new char[size];
}
catch (Exception)
{
}
}
public IntPtr AllocCoTaskMem()
{
if (this.buffer.Length == 0) return IntPtr.Zero;
IntPtr destination = Marshal.AllocCoTaskMem(this.buffer.Length * 2);
Marshal.Copy(this.buffer, 0, destination, this.buffer.Length);
return destination;
}
public string GetString()
{
int offset = this.offset;
while ((offset < this.buffer.Length) && (this.buffer[offset] != '\0'))
{
offset++;
}
string str = new string(this.buffer, this.offset, offset - this.offset);
if (offset < this.buffer.Length)
{
offset++;
}
this.offset = offset;
return str;
}
public void PutCoTaskMem(IntPtr ptr)
{
Marshal.Copy(ptr, this.buffer, 0, this.buffer.Length);
this.offset = 0;
}
public void PutString(string s)
{
int count = Math.Min(s.Length, this.buffer.Length - this.offset);
s.CopyTo(0, this.buffer, this.offset, count);
this.offset += count;
if (this.offset < this.buffer.Length)
{
this.buffer[this.offset++] = '\0';
}
}
}
private string CharRangeToString(NativeMethods.CHARRANGE c)
{
NativeMethods.TEXTRANGE lParam = new NativeMethods.TEXTRANGE();
lParam.chrg = c;
int size = (c.cpMax - c.cpMin) + 1;
CharBuffer buffer = new CharBuffer(size);
IntPtr ptr = buffer.AllocCoTaskMem();
if (ptr == IntPtr.Zero)
{
return "";
}
lParam.lpstrText = ptr;
int num1 = (int)NativeMethods.SendMessage(new HandleRef(this, this.Handle), 1099, 0, lParam);
buffer.PutCoTaskMem(ptr);
if (lParam.lpstrText != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(ptr);
}
return buffer.GetString();
}
I hope this will help you. For me this works perfect. But remember that when you insert the hyperlink that way, you mark it protected, so you can't edit it directly in the RichTextBox. And changing the hyperlinks is another topic.
Good luck.
Cheers,
Alex.
Alex KraS
|
|
|
|
|
Thanks a lot, you sure put me in the right direction . The arbitrary links looks a lot better. For those who still want to use the file://somefile, replace each space in the link with '%20', no quotes of course.
Cheers,
Frank
|
|
|
|
|
Hi Aleksei, great peice of work! but was wondering how you change the indentations on the ruler to match the page margin, let me explain in more detail
For example:
If i change the ruler margins to 1 Inch(25.4mm) each side id expect the Ruler indetation pegs to adjust to the edge of the newly set margin, however you must change the ruler indentation settings to affect these, which in turn alters the Rich Text box indentation level therefore messing with the print
So what im asking is how can i set the ruler margins and change the ruler indents posistion without changing the Rich text box's indentation level?
Any Ideas?
Thanks
modified on Sunday, December 21, 2008 3:50 AM
|
|
|
|
|
Hi
Your control is very useful for me but there is a little problem. I have some rtf formatted text and now I want to display this text in the text editor
this.ateAdditionalNote.TextEditor.Rtf = text;
Unfortunately no text is displayed in the control although the property (TextEditor.Rtf) has the right value. When I save the text in a file and open it in MS Word, the text is displayed correctly.
Do I have to call some kind of refresh method or something similar?
Thank you for your help!
Michael Hachen
|
|
|
|
|
Hm. I can't tell you exactly, what can be wrong with it. For me it works fine. What kind of text are you assigning to Rtf property (I mean formatting)?
Alex KraS
|
|
|
|
|
OK I figured it out. If I set the Rtf property BEFORE the text editor is shown (.Show() or .ShowDialog()) the property is set but the text won't be displayed. If I set the Rtf property AFTER the editor is shown, the text will be displayed correctly.
Strange but I can live with it...
Mike Hachen
|
|
|
|
|
I am glad that you've found the solution.
If you have any problems, do not hesitate to contact me.
Alex KraS
|
|
|
|
|
Hi,
There is in your code a region called "Old Style Formating", but it seems to appears that this piece of code is never used, is it true ?
Because i will adapt your font code to my program in vb.net and have some problems to make the translation.
Thanks
|
|
|
|
|
Hello!
Yes, this region was used in the first version of the component, but now it is obsolete. So, you can remove it or keep as an example. All formatting options may be changed through SelectionFont2 and SelectionCharStyle. In about 2 days I plan to upload updated version with many improvements and bug fixies.
Regards, Alex.
Alex KraS
|
|
|
|
|
when you upload your new code?
|
|
|
|
|
G'day Aleksei.
I'm trying to translate you code from C# to vb using Lutz Roeder's .Net Reflector. The ruler translation seems to go OK but the Enhanced Editor is giving me some trouble. After translating I can build the dll containing both controls. I then add them to a form and all seems to go well. However, after saving and closing this form I cannot open it again in the designer view. It return the following errors;
One or more errors encountered while loading the designer.
The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.
The variable 'CharStyle1' is either undeclared or was never assigned.
The variable 'CharStyle1' is either undeclared or was never assigned.
The variable 'CharStyle1' is either undeclared or was never assigned.
The variable 'CharStyle1' is either undeclared or was never assigned.
The variable 'CharStyle1' is either undeclared or was never assigned.
The variable 'ParaLineSpacing1' is either undeclared or was never assigned.
The variable 'ParaLineSpacing1' is either undeclared or was never assigned.
The variable 'ParaListStyle1' is either undeclared or was never assigned.
The variable 'ParaListStyle1' is either undeclared or was never assigned.
The variable 'ParaListStyle1' is either undeclared or was never assigned.
The variable 'ParaListStyle1' is either undeclared or was never assigned.
Checking the InitializeComponent part of the form doesn't reveale an error. After removing the coding for the Editor the form is displayed again.
If I try to add your ExtendedRichTextBox control to my problem I reveice the same errors. Any suggestions?
Cheers,
Frank
|
|
|
|
|
It's all about Visual Studio 'manners'. For me, it demands all objects to be marked public . And if they are internal designer fails. Also, you may check if [Serializable()] (<Serializable> _ in VB) attribute is set. Try this out and let me know.
Regards,
Alex
Alex KraS
|
|
|
|
|
G'day.
I translated it to VS2008 and I don't get this error anymore. I didn't try your suggestion, sorry for that.
How did you intent to use the OffsetType? The line
this.TextEditor.SelectionOffsetType = ExtendedRichTextBox.OffsetType.Subscript; doesn't seem te be enough. Do I have to set the offset like this?
this.TextEditor.SelectionCharOffset = -5;
Cheers,
Frank
|
|
|
|
|
Hi,
I have the same problem and the <serializable ()=""> _ is set too, below is the code
Imports System.Diagnostics
Imports System.Collections
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports System.Drawing.Printing
Imports System.ComponentModel
Imports System.Security.Permissions
''' <summary>
''' This ExtendedRichTextBox is based on .NET Framework and also uses WinAPI
''' to extend its functionality. It also contains wrappers for TOM
''' (Text Object Model) and for OLE (Object Linking and Embedding - this
''' code was written by Oscar Londoño, go to
'''
''' http://www.codeproject.com/KB/edit/MyExtRichTextBox.aspx
'''
''' for more details)
''' </summary>
<Serializable()> _
Public Class ExtendedRichTextBox
Inherits RichTextBox
#Region "CONSTRUCTOR"
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function LoadLibrary(ByVal libname As String) As IntPtr
End Function
Private Shared RichEditModuleHandle As IntPtr
'Libraries
Private Const RichEditDllV3 As String = "RichEd20.dll"
Private Const RichEditDllV41 As String = "Msftedit.dll"
'You can also specify
and so on .....
Please help its urgent.
modified on Monday, July 18, 2011 3:03 AM
|
|
|
|
|
This my Forms Designer code.
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Editor
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Dim CharStyle1 As ExtendedRichTextBox.CharStyle = New ExtendedRichTextBox.CharStyle
Dim ParaLineSpacing1 As ExtendedRichTextBox.ParaLineSpacing = New ExtendedRichTextBox.ParaLineSpacing
Dim ParaListStyle1 As ExtendedRichTextBox.ParaListStyle = New ExtendedRichTextBox.ParaListStyle
Me.ExtendedRichTextBox1 = New ExtendedRichTextBox
Me.MenuStrip1 = New System.Windows.Forms.MenuStrip
Me.ToolStrip1 = New System.Windows.Forms.ToolStrip
Me.ToolStrip2 = New System.Windows.Forms.ToolStrip
Me.StatusStrip1 = New System.Windows.Forms.StatusStrip
Me.SuspendLayout()
'
'ExtendedRichTextBox1
'
Me.ExtendedRichTextBox1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.ExtendedRichTextBox1.Location = New System.Drawing.Point(0, 77)
Me.ExtendedRichTextBox1.Name = "ExtendedRichTextBox1"
Me.ExtendedRichTextBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes
CharStyle1.Bold = False
CharStyle1.Italic = False
CharStyle1.Link = False
CharStyle1.Strikeout = False
CharStyle1.Underline = False
Me.ExtendedRichTextBox1.SelectionCharStyle = CharStyle1
Me.ExtendedRichTextBox1.SelectionFont2 = New System.Drawing.Font("Microsoft Sans Serif", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Inch)
ParaLineSpacing1.ExactSpacing = 0
ParaLineSpacing1.SpacingStyle = ExtendedRichTextBox.ParaLineSpacing.LineSpacingStyle.Unknown
Me.ExtendedRichTextBox1.SelectionLineSpacing = ParaLineSpacing1
ParaListStyle1.BulletCharCode = CType(0, Short)
ParaListStyle1.NumberingStart = CType(0, Short)
ParaListStyle1.Style = ExtendedRichTextBox.ParaListStyle.ListStyle.NumberAndParenthesis
ParaListStyle1.Type = ExtendedRichTextBox.ParaListStyle.ListType.None
Me.ExtendedRichTextBox1.SelectionListType = ParaListStyle1
Me.ExtendedRichTextBox1.SelectionOffsetType = ExtendedRichTextBox.OffsetType.None
Me.ExtendedRichTextBox1.SelectionSpaceAfter = 0
Me.ExtendedRichTextBox1.SelectionSpaceBefore = 0
Me.ExtendedRichTextBox1.Size = New System.Drawing.Size(608, 360)
Me.ExtendedRichTextBox1.TabIndex = 0
Me.ExtendedRichTextBox1.Text = ""
'
'MenuStrip1
'
Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
Me.MenuStrip1.Name = "MenuStrip1"
Me.MenuStrip1.Size = New System.Drawing.Size(608, 24)
Me.MenuStrip1.TabIndex = 1
Me.MenuStrip1.Text = "MenuStrip1"
'
'ToolStrip1
'
Me.ToolStrip1.Location = New System.Drawing.Point(0, 24)
Me.ToolStrip1.Name = "ToolStrip1"
Me.ToolStrip1.Size = New System.Drawing.Size(608, 25)
Me.ToolStrip1.TabIndex = 2
Me.ToolStrip1.Text = "ToolStrip1"
'
'ToolStrip2
'
Me.ToolStrip2.Location = New System.Drawing.Point(0, 49)
Me.ToolStrip2.Name = "ToolStrip2"
Me.ToolStrip2.Size = New System.Drawing.Size(608, 25)
Me.ToolStrip2.TabIndex = 3
Me.ToolStrip2.Text = "ToolStrip2"
'
'StatusStrip1
'
Me.StatusStrip1.Location = New System.Drawing.Point(0, 440)
Me.StatusStrip1.Name = "StatusStrip1"
Me.StatusStrip1.Size = New System.Drawing.Size(608, 22)
Me.StatusStrip1.TabIndex = 4
Me.StatusStrip1.Text = "StatusStrip1"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(608, 462)
Me.Controls.Add(Me.StatusStrip1)
Me.Controls.Add(Me.ToolStrip2)
Me.Controls.Add(Me.ToolStrip1)
Me.Controls.Add(Me.ExtendedRichTextBox1)
Me.Controls.Add(Me.MenuStrip1)
Me.MainMenuStrip = Me.MenuStrip1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents ExtendedRichTextBox1 As ExtendedRichTextBox
Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
Friend WithEvents ToolStrip1 As System.Windows.Forms.ToolStrip
Friend WithEvents ToolStrip2 As System.Windows.Forms.ToolStrip
Friend WithEvents StatusStrip1 As System.Windows.Forms.StatusStrip
End Class
Please Please Please help. The Warnings it show in VB 2005 are
The variable 'CharStyle1' is either undeclared or was never assigned.
The variable 'ParaLineSpacing1' is either undeclared or was never assigned.
The variable 'ParaListStyle1' is either undeclared or was never assigned.
The Code runs ok, but when I want to goto design mode then it shows thses warning. Please help me as soon as possible.
|
|
|
|
|
How much of this is posible in VB? i'm making a similar thing in VB 2008 EE, so i was wondering if you could give me any help in that direction? Maybe even a vb project file ?
Also: Where did you find your undo, redo icons? and did you make the U, I, B... Etc. icons yourself? if not where did oyu get them ?
|
|
|
|
|
Unfortunately, I don't have VB project, because everything is written in C#. But you can convert it into VB with no doubt. You can make it manually or use converters. I'm sure that there are many of them in the Internet.
If you need any assistance, you're welcome.
P.S.
Icons are taken from Microsoft Image Library. I got it with the trial version of VS 2008 Pro.
Alex KraS
|
|
|
|
|
it might be a bit to long to write it all again so maybe you could just look at this: http://www.vbforums.com/showthread.php?p=3293834#post3293834
|
|
|
|
|
hi
|
|
|
|
|
Hi,
sorry to ask.
I want to use the ruler for milimeter on the screen, one horizontal, one vertical.
When I have a display with 1920*1200, which value for the zoomfactor?
When I set the factor to 1, it's displaying too big on the screen.
I tried some things to get the right factor, but I didn't get a right value/display.
Can somebody help me?
Greetings,
Peter
|
|
|
|
|
Hello, Peter.
That is known issue. The probles is that Ruler does not support zoom change (for now).
I am currently working on that. I hope to upgrade the project soon.
Alex
Alex KraS
|
|
|
|
|