开发者

I am creating a text editor app in C#...few bugs i cant overcome

开发者 https://www.devze.com 2023-02-12 19:53 出处:网络
In my app, when I create a new window (form2) (from file>new) and close the previous window (Form1), the newly created window (form2) closes as well. How do i make sure that only the window I close i
  1. In my app, when I create a new window (form2) (from file>new) and close the previous window (Form1), the newly created window (form2) closes as well. How do i make sure that only the window I close is closed? For example, when form1 and form2 are open and I close form1, I want f开发者_高级运维orm2 to remain open.

  2. I use a RichTextBox in the editor. How do I go to a particular line when I specify a line number in a text box?

  3. I want to create a drop-down color chooser from the tool strip (like in Word or Excel). How can I do this?

its not a dialog box and a code snippet that moves the cursor to particular line when given in Text box is appreciate...


1) Can you post a code snippet showing how you're creating the second window? Are you setting the owner property?

2) My bet would the CaretPosition property.

3) Take a look at this. The author just create a form with the floatting drop drown and then proceeds to show it, hide it, ... when appropriate. Clever and down to earth.


  1. more info needed

  2. count up the length of each line before the line you want to goto, then just set the SelectionStart property to that value;

  3. Have you looked at the default ColorDialog control?


Here is code I have used to fill two list boxes with all system colours and theme colours. Perhaps you could adapt for use in a combo box?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

  /// <summary>
        /// loads the colours
        /// </summary>
        private void LoadColours()
        {
            try
            {
                Color testColor = ProfessionalColors.ButtonCheckedGradientBegin;
                Type colorType = testColor.GetType();

                PropertyInfo[] propInfoList = colorType.GetProperties( BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public );

                lvColours.Items.Clear();

                foreach ( PropertyInfo oPropertyInfo in propInfoList )
                {
                    Color color = ( Color ) oPropertyInfo.GetValue( null, null );

                    ListViewItem oListViewItem = new ListViewItem( GetColorName( oPropertyInfo.Name ) );

                    oListViewItem.BackColor = color;

                    lvColours.Items.Add( oListViewItem );
                }

                Type ProfType = typeof( ProfessionalColors );

                PropertyInfo[] PropInfos = ProfType.GetProperties( BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public );

                foreach ( PropertyInfo oPropertyInfo in PropInfos )
                {
                    Color oColor =(Color) oPropertyInfo.GetValue( null, null );

                    ListViewItem oListViewItem = new ListViewItem( GetColorName( oPropertyInfo.Name ) );

                    oListViewItem.BackColor = oColor;

                    lvProfessionalColours.Items.Add( oListViewItem );
                }
            }
            catch ( Exception ex )
            {
                MessageBox.Show( ex.Message );
            }
        }

    /// <summary>
    /// Gets the Color Name
    /// </summary>
    protected string GetColorName( string strFullName )
    {
        string strName = "";
        int idx = strFullName.LastIndexOf( "." );
        if ( idx != -1 )
        {
            strName = strFullName.Substring( idx );
        }
        else
        {
            return strFullName;
        }
        return strName;
    }


If the first form is passed to Application.Run() then it will terminate the whole program when you close it. Instead of closing the form, you can simply hide it.

0

精彩评论

暂无评论...
验证码 换一张
取 消