none
Deleted

Answers

  • The toolbar/ribbon in question would be able to edit any text that resides inside the various richtextboxes and datagridview objects that I have in the program. I want the toolbar/ribbon visible at all times so that it is obvious that the text can be changed no matter where you are at.

    Most of that requirement is not relevant to the toolbar - it is to do with the editing functions that you want to implement for the different user controls.  You should consider the two sides of the task as two separate issues.  The toolbar is simply a mechanism that allows the user to select the option - there will invariably be other ways that the options can be selected, such as a shortcut key or a menu item. Take one of your tasks (changing font, perhaps) and implement it using a menu item or a button or anything that is really simple.  Then move onto the next task.  When you have some of these working, then you can decide which ones can be included as toolbar options, and you can implement the toolbar. 

    Your 'universal' toolbar will need a means of identifying the control to be edited.  This is usually done by providing a property as part of the toolbar class that is updated with the control to be edited.  So when methods in the toolbox class are invoked, these methods consult the property value and know which control they are required to work with.

    You can implement this without a custom toolbar by creating a global variable that you will update with the 'current' control, so when your editing methods, which initially will be part of the form class code, are invoked they actually look up that value and operate on that control.   When all that is working you can consider embedding the code into the toolbar class instead of the form class and creating the relevant property in the toolbar class - the code changes required to do that are trivial.

    Thursday, October 30, 2014 5:12 AM

All replies

  • I've looked for examples from others online but haven't found anything specific for some reason.

    You are unlikely to find anything that is specific to your requirement - you should take an example that is close to what you need and modify it to meet your particular application.
    http://www.codeproject.com/Articles/30799/Extended-RichTextBox

    If you want to be able to re-use the combined RTB and toolbar then you can create a custom control.
    http://msdn.microsoft.com/en-us/library/ms996443.aspx 

    Sunday, October 26, 2014 4:30 AM
  • Deleted
    Sunday, October 26, 2014 4:52 AM
  • I don't know why you can't use a regular toolbox style toolbar of some type to do what you want to do. I think you could use a Control.ContextMenuStrip with a RichTextBox to implement something along the lines of what you need. 

    Anyhow I just used two buttons. One to launch a Font Dialog and the other to launch a Color Dialog for altering selected text's Font or Forecolor using the Font Dialog or backcolor using the Color Dialog.

    However the Font Dialog has a limited range of colors available as can be seen in the 2nd pic below. So perhaps you would want to use a Color Dialog to set the selected text's color instead. I would suppose in the Button2 click event you could make an If statement so the user somehow selects ahead of time whether it's the selected text's color or backcolor to be altered.

    Option Strict On
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Using FD As New FontDialog
                With FD
                    .AllowScriptChange = True
                    .FixedPitchOnly = False
                    .ShowColor = True
                    .ShowEffects = True
                    .AllowVectorFonts = True
                    .AllowVerticalFonts = True
                End With
                If RichTextBox1.SelectionLength > 0 Then
                    If FD.ShowDialog = Windows.Forms.DialogResult.OK Then
                        RichTextBox1.SelectionFont = FD.Font
                        RichTextBox1.SelectionColor = FD.Color
                    End If
                End If
            End Using
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Using CD As New ColorDialog
                With CD
                    .AllowFullOpen = True
                    .AnyColor = True
                    .FullOpen = True
                End With
                If RichTextBox1.SelectionLength > 0 Then
                    If CD.ShowDialog = Windows.Forms.DialogResult.OK Then
                        RichTextBox1.SelectionBackColor = CD.Color
                    End If
                End If
            End Using
        End Sub
    
    End Class


    La vida loca


    Sunday, October 26, 2014 5:18 AM
  • Okay well that's a little closer. So with that first reference you gave me, what does it mean when it references a DLL in the references. I know what adding references is as of today but I'm not sure on what the link means by DLL

    Do you mean "Basically if you just need to use the control on your form, you can simply add the DLL as a reference, ..."?

    The project has been prepared as a DLL that you add as a reference in your project.  That then allows you to add the custom control to your toolbox, and use as a design-time component like you use the standard controls provided with .Net.

    If you want to change it then download the project (not just the DLL), and open the project in VS.  It will open as a 'Class Library'.
    http://msdn.microsoft.com/en-us/library/f1yh62ef(v=vs.90).aspx

    Sunday, October 26, 2014 5:36 AM
  • Maybe this is more like what you would like. I suppose you could assign this ContextMenuStrip to any RichTextBox. I didn't try that.

    Option Strict On
    
    Imports System.ComponentModel
    
    Public Class Form1
    
        Private WithEvents ContextMenuStrip1 As New ContextMenuStrip
        Private WithEvents ToolStripMenuItem1 As New ToolStripMenuItem
        Private WithEvents ToolStripMenuItem2 As New ToolStripMenuItem
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
            ToolStripMenuItem1.Name = "ToolStripMenuItem1"
            ToolStripMenuItem1.Text = "RTB selection Font and ForeColor."
            AddHandler ToolStripMenuItem1.Click, AddressOf ToolStripItemsClicked_Click
            ToolStripMenuItem2.Name = "ToolStripMenuItem2"
            ToolStripMenuItem2.Text = "RTB selection BackColor."
            AddHandler ToolStripMenuItem2.Click, AddressOf ToolStripItemsClicked_Click
            ContextMenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {ToolStripMenuItem1, ToolStripMenuItem2})
            ContextMenuStrip1.Name = "contextMenuStrip1"
            ContextMenuStrip1.Size = New System.Drawing.Size(200, 70)
            RichTextBox1.ContextMenuStrip = ContextMenuStrip1
        End Sub
    
        Public Sub ToolStripItemsClicked_Click(sender As Object, e As EventArgs)
            Dim RTBSelStart As Integer = 0
            If DirectCast(sender, ToolStripMenuItem).Name = "ToolStripMenuItem1" Then
                Using FD As New FontDialog
                    With FD
                        .AllowScriptChange = True
                        .FixedPitchOnly = False
                        .ShowColor = True
                        .ShowEffects = True
                        .AllowVectorFonts = True
                        .AllowVerticalFonts = True
                    End With
                    If RichTextBox1.SelectionLength > 0 Then
                        RTBSelStart = RichTextBox1.SelectionStart
                        If FD.ShowDialog = Windows.Forms.DialogResult.OK Then
                            RichTextBox1.SelectionFont = FD.Font
                            RichTextBox1.SelectionColor = FD.Color
                            RichTextBox1.SelectionStart = RTBSelStart
                            RichTextBox1.SelectionLength = 0
                        End If
                    End If
                End Using
            ElseIf DirectCast(sender, ToolStripMenuItem).Name = "ToolStripMenuItem2" Then
                Using CD As New ColorDialog
                    With CD
                        .AllowFullOpen = True
                        .AnyColor = True
                        .FullOpen = True
                    End With
                    If RichTextBox1.SelectionLength > 0 Then
                        RTBSelStart = RichTextBox1.SelectionStart
                        If CD.ShowDialog = Windows.Forms.DialogResult.OK Then
                            RichTextBox1.SelectionBackColor = CD.Color
                            RichTextBox1.SelectionStart = RTBSelStart
                            RichTextBox1.SelectionLength = 0
                        End If
                    End If
                End Using
            End If
        End Sub
    
    End Class


    La vida loca


    Sunday, October 26, 2014 5:51 AM
  • Deleted
    Sunday, October 26, 2014 6:19 AM
  • Okay I'm sorry, I'm getting a little lost. So is there not a way to make the same type of toolbar like the one that is above where we type these replies back and forth? I'm very new to all the terms that you guys are using. I am basically using 5 different richtextbox areas to display different things that can be edited from day to day. I know that the users that this program is for will want to change the fonts and colors just like you can quickly in Microsoft Word. Is the toolbar I am thinking of possible in visual basic? Or am I expecting too much too soon?

    There's two types of "toolbars" available in your ToolBox. One is a ToolStrip and the other is a MenuStrip.

    There is also a ToolStripContainer in your ToolBox. It is not required in order to use a ToolStrip but provides some functionality you may want.

    At least the above are in my ToolBox.

    ToolStrip Control Overview (Windows Forms)

    ToolStripContainer Control Overview

    MenuStrip Control Overview (Windows Forms)

    I would suppose you could use either a ToolStrip or MenuStrip. I believe a ToolStrip you would use Buttons with.

    A MenuStrip is more like the toolbar at the top of Notepad where it has words and you select a word and other words appear underneath a word. Then you select one of those words to do something.

    In either instance if you drag the control from the toolbox and place it on your form then add an item you can click on the item which will add an event handler for the item into your Forms code window.

    So with a MenuStrip dragged onto the Form I could type a name into a location, click on that item and create an event handler for that Item in the code window. Or instead add sub items to it and click on each sub item to create an event handler in the code window.

    For example in the image below selecting File lists options available under File. But File itself doesn't do anything other than display the sub items in File. However if there was an event handler for File in Notepads code it could be made to do something too but since there isn't any it's just used to display its sub items. Of course you wouldn't want an event handler for it since it isn't supposed to do anything other than display its sub items.


    La vida loca



    Sunday, October 26, 2014 8:12 AM
  • This is a Form in Designer with a MenuStrip dragged onto it. Then I typed a word in the left most text area. And below that a word in two more areas. Then I clicked on the bottom two words and Event Handlers for those words were added to Forms code window.

    When the Form is launched selecting the word Hello only displays the sub items under Hello. If I had added code to either of the event handlers for those sub items then if I selected one of them something would happen.

    Public Class Form1
    
        Private Sub WhaasUpToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles WhaasUpToolStripMenuItem.Click
    
        End Sub
    
        Private Sub HolaToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles HolaToolStripMenuItem.Click
    
        End Sub
    End Class


    La vida loca

    Sunday, October 26, 2014 8:29 AM
  • I am currently trying to get a toolbar (I might be calling it the wrong thing...) to show up in a richtextbox. I want it to have the options to change font size. Make text bold, italicized, and underlined. Give text a highlighted color and other things that are common to a program like Microsoft Word.

    I've thought of making a "Preferences" or "Settings" type menustripitem form that would let you customize them but I figured the toolbar would be more convenient obviously. 

    I've looked for examples from others online but haven't found anything specific for some reason. I AM fairly new to programming but I have a pretty good program going so far. 

    I have several richtextbox locations to add this to. Don't know that it makes a difference. 

    Any ideas or suggestions would be appreciated!

    Thanks!

    If you're willing to look into buying third-party components, you might try this one.

    It's quite robust - to give you an idea of just how easy some of it is, have a look here and click the "Getting Started" link.


    Still lost in code, just at a little higher level.

    :-)

    Sunday, October 26, 2014 8:11 PM
  • Okay I'm sorry, I'm getting a little lost. So is there not a way to make the same type of toolbar like the one that is above where we type these replies back and forth?

    You should indicate exactly why the examples you have seen are not suitable for what you need to do.  A toolbar is just a collection of buttons or menu options that allow you to select things.  It can be attached to a control (a RTB, for instance) or it can be a separate movable sizeable window.   There's nothing particularly magic about it.   If you want to start from scratch with the simplest possible approach, just put a row of buttons across the top of your form.  Once you can make these work then you can adjust the appearance to anything you want.

    Sunday, October 26, 2014 8:58 PM
  • Deleted
    Wednesday, October 29, 2014 8:36 AM
  • Do you think I could use a ribbon in order to accomplish this? If it was a universal editing toolbar type object then that would work perfectly. Any thoughts?

    Seriously? I'm not certain I've ever heard of a universal editing toolbar.

    What's the issue with using either a Toolstrip, MenuStrip or ContextMenuStrip? Any of them created can be used with all the RichTextBox's.

    I created a single ContextMenuStrip and set RichTextBox1.ContextMenuStrip = ContextMenuStrip1. So all RichTextBox's could be set to use ContextMenuStrip1. You only need one. All the code is there. And if you right click in any RichTextBox that uses ContextMenuStrip1 as its ContextMenuStrip then your editing capability appears. If your ContextMenuStrip1 is in Form1 and you have Form2 with a RichTextBox on it then set that RichTextBox so its ContextMenuStrip is Form1.ContextMenuStrip1.

    I suspect with MenuStrips or ToolStrips it would be simple enough to make all RichTextBox's use one. Or if your RichTextBox's are on different Forms then provide one for each Form.

    Why reinvent the wheel?


    La vida loca



    Wednesday, October 29, 2014 10:46 AM
  • If it was a universal editing toolbar type object then that would work perfectly.

    It appears that you want your toolbar to do something different than what the typical toolbars, such as the examples you found and the example I provided, do.  You should explain what that difference is.  Then it may be possible to indicate whether a ribbon, or something else, is most suitable.

    A 'universal' editing toolbar is simply an ordinary toolbar with embedded code that operates on an editable object. it differs in structure slightly from a customized toolbar, but the actual code is almost exactly the same.

    Wednesday, October 29, 2014 12:00 PM
  • Deleted
    Thursday, October 30, 2014 4:13 AM
  • The toolbar/ribbon in question would be able to edit any text that resides inside the various richtextboxes and datagridview objects that I have in the program. I want the toolbar/ribbon visible at all times so that it is obvious that the text can be changed no matter where you are at.

    Most of that requirement is not relevant to the toolbar - it is to do with the editing functions that you want to implement for the different user controls.  You should consider the two sides of the task as two separate issues.  The toolbar is simply a mechanism that allows the user to select the option - there will invariably be other ways that the options can be selected, such as a shortcut key or a menu item. Take one of your tasks (changing font, perhaps) and implement it using a menu item or a button or anything that is really simple.  Then move onto the next task.  When you have some of these working, then you can decide which ones can be included as toolbar options, and you can implement the toolbar. 

    Your 'universal' toolbar will need a means of identifying the control to be edited.  This is usually done by providing a property as part of the toolbar class that is updated with the control to be edited.  So when methods in the toolbox class are invoked, these methods consult the property value and know which control they are required to work with.

    You can implement this without a custom toolbar by creating a global variable that you will update with the 'current' control, so when your editing methods, which initially will be part of the form class code, are invoked they actually look up that value and operate on that control.   When all that is working you can consider embedding the code into the toolbar class instead of the form class and creating the relevant property in the toolbar class - the code changes required to do that are trivial.

    Thursday, October 30, 2014 5:12 AM
  • Deleted
    Thursday, October 30, 2014 5:22 AM
  • Let me know if there is a simple code for the Bold part!

    Fonts are immutable - be sure to look at some on-line examples to see the code to use to change a font.  For instance:
    http://msdn.microsoft.com/en-us/library/system.drawing.font.bold(v=vs.110).aspx

    Thursday, October 30, 2014 5:39 AM
  • Deleted
    Thursday, October 30, 2014 7:11 AM
  • Is there a way to change this one to make the highlight color change for the selected text? This is like the last thing that I need for this part of the program!

    I'm not sure that you can - I think this is a Windows system setting ('Selected Text').   If you can find a property of the RTB that sets this item then the code would be nearly the same as you have posted, but I don't think there is such a property.
    Thursday, October 30, 2014 7:26 AM