Welcome to Dream.In.Code
Become a VB Expert!

Join 149,954 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,329 people online right now. Registration is fast and FREE... Join Now!




Menu

 
Reply to this topicStart new topic

Menu

sam_benne
18 Jan, 2008 - 11:38 AM
Post #1

D.I.C Regular
Group Icon

Joined: 16 Jan, 2008
Posts: 368



Thanked: 2 times
Dream Kudos: 400
My Contributions
Hi I was wondering if any one can help me, I am creating a menu and have got most of the codes working but I can't get or find some of the codes I need such as "undo", "redo","Justify" and "small caps". if any one knows how to do these please can you help. Also these commands will be editing text in a rich text box. Please help.
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Menu
19 Jan, 2008 - 04:56 AM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
We're not just going to write code for you! You at least have to attempt it yourself.

RichTextBox does not have a Justify alignment option. It only supports left, center, right.

"small caps" can be emulated by capitalising the selected text, and making it a smaller font.

You will have to implement undo/redo commands yourself
You will need
  • An array of strings
  • An index to the current location of the array
That's two variables. Then when text is changed in the rich text box you can store it at the current location in the array and increment the location.

Undo will decrement the location and put that text back in the rich text box.

Redo will decrement the location and put that text back into the rich text box.



This post has been edited by Nayana: 19 Jan, 2008 - 04:57 AM
User is offlineProfile CardPM
+Quote Post

sam_benne
RE: Menu
19 Jan, 2008 - 09:49 AM
Post #3

D.I.C Regular
Group Icon

Joined: 16 Jan, 2008
Posts: 368



Thanked: 2 times
Dream Kudos: 400
My Contributions
QUOTE(Nayana @ 19 Jan, 2008 - 05:56 AM) *

We're not just going to write code for you! You at least have to attempt it yourself.

RichTextBox does not have a Justify alignment option. It only supports left, center, right.

"small caps" can be emulated by capitalising the selected text, and making it a smaller font.

You will have to implement undo/redo commands yourself
You will need
  • An array of strings
  • An index to the current location of the array
That's two variables. Then when text is changed in the rich text box you can store it at the current location in the array and increment the location.

Undo will decrement the location and put that text back in the rich text box.

Redo will decrement the location and put that text back into the rich text box.


I have had ago at the undo but the code doesn't seem to work and i know if i can get this to work I can change it a bit to become redo aswell.
CODE

            Case "Undo"
            ActiveForm.rtf.SelUndo = Not ActiveForm.rtfText.SelUndo
            Button.Value = IIf(ActiveForm.rtfText.SelUndo, tbrPressed, tbrUnpressed)



User is offlineProfile CardPM
+Quote Post

Nayana
RE: Menu
20 Jan, 2008 - 03:15 AM
Post #4

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
There is no such command as SelUndo on a RichTextBox what are you trying to do?

You didn't even try my suggestion before coming back here.

The RichTextBox can be told to undo, but it only remembers the last thing that happened to it. I.e. you cannot under more than once.

It is supposed to support multi-level undo, but it really doesn't.

To send it the message, you will need to declare the following functions and enumerations. You should probably do this in a seperate file (add a module)

CODE

Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Const WM_USER = &H400
Public Const EM_UNDO = &HC7
Public Const EM_REDO = (WM_USER + 84)


Then to tell it to undo/redo:
CODE

Public Sub Undo()
    SendMessageLong rtfText.hwnd, EM_UNDO, 0, 0
End Sub
Public Sub Redo()
    SendMessageLong rtfText.hwnd, EM_REDO, 0, 0
End Sub


The first time you do Undo, it will undo, but the second time, it will actually do a Redo. So it really isn't that much use. There is a command you can send to it to tell it to have multiple levels of undo, but it doesn't work.

If you want to do that then you will have to do it the way I described in my first post.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 05:58PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month