Results 1 to 3 of 3

Thread: [2008] Insert image of line into RTB

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    [2008] Insert image of line into RTB

    Hey,

    I am making a code editor using a RTB. I would like to add a feature to my code editor similar to the behaviour of the VS IDE: it draws a line between two subs/functions etc.

    The code my code editor will process is delimited by blocks of brackets, something like C, like this:
    Code:
    'sub' name
    {
       'event' name
       {
           code
       }
    }
    I would like my program to draw a line beneath the last closing bracket }, denoting the end of that block. So you would basically get:
    Code:
    'sub' name
    {
       'event' name
       {
           code
       }
    }
    ______________________________________
    'sub' name 2
    {
        ... etc
    }
    ______________________________________

    I have tried various ways and multiple times to draw the line using GDI+ but have come to the conclusion that it is very troublesome... I never managed it even slightly. You can't use any Paint events for the RTB which is the main reason it is hard to do, and having the line scrolled together with the text was also a pain.

    I am now trying my last idea before giving up on this... I thought of inserting an image of a line into the RTB.

    Now there are a few things I need clearing up on because I have never used images in RTB's before.

    - Is it possible to make the line behave as though it was just a line, not an actual picture the user can manipulate, select etc..?
    - If I save the contents of the RTB to file using RTB.SaveFile(path, PlainText), will the lines (images) be simply omitted, or will I have to deal with them? (the images must obviously NOT be present in the resulting code file, since other programs have to deal with those files)
    - Will the image automatically move down a line when I insert a linefeed above it, just like it would do in Word for example?


    And generally, is this a good idea, or am I missing a few important facts that might make this impossible?

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [2008] Insert image of line into RTB

    To add image to richtextbox you can do something as simple as this:
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
        Dim img As New System.Drawing.Bitmap("c:\test.bmp")
        Clipboard.SetDataObject(img)
        RichTextBox1.Paste()
    
    End Sub

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [2008] Insert image of line into RTB

    Thanks, I got it to insert the picture.

    But, the user can interact with it.

    I want the picture to be like part of the background of the RTB. You cannot select it, delete it whatever, it just has to move together with the text like it normally does.
    Right now, when you select it and press enter for example it is gone...

    How can I do this?


    EDIT
    Also, I didn't think it was a very good idea to modify the Clipboard without the user noticing. I don't know if it worked for all kinds of data that can be stored in the Clipboard, but I tried to save the Clipboard.GetDataObject to an Object variable, then after using your code resetting it via Clipboard.SetDataObject. Will this work?
    Last edited by NickThissen; Feb 16th, 2008 at 01:27 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width