Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9098789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:26:48+00:00 2026-06-17T00:26:48+00:00

I’m trying to make a simple text editor that colors text in real time.

  • 0

I’m trying to make a simple text editor that colors text in real time. I also must use DLL and Reflection for this.
I want to color the text while user typing. For that reason I have a checkbox. If it checked the text will be colored while user is typing (Real Time).

I’ve wrote a DLL file to do that.

Anyway, I’m very new to reflection thing.

  • The question:

I would want to ask you guys for your professional advice whether what I’ve wrote can be called “using reflection” or not? and if it’s not, can point me what is wrong?

Here is my code (I’ve removed many things from it so the code will reflect the question but there might be leftovers)

using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Reflection;

namespace Editor
{
    public class MainForm : Form
    {
        //Declaration of Controls 
        private RichTextBox EditRichTextBox;
        private CheckBox chkBox;
        private int flag = 0;

        private Button[] PlugButton;
        public string[] PluginNames;
        private int NumofPlugins;

        public MainForm()
        {
            //Initialization of Controls
            this.EditRichTextBox = new RichTextBox();
            this.ErrorTextBox = new RichTextBox();
        this.chkBox = new CheckBox();

            //Form
            this.ClientSize = new Size(700, 500);
            this.Name = "MainForm";
            this.Text = "C# Editor";

            //EditRichTextBox
            this.EditRichTextBox.Location = new Point(20, 20);
            this.EditRichTextBox.Name = "EditRichTextBox";
            this.EditRichTextBox.Size = new Size(this.Width - 150, 300);
            this.EditRichTextBox.AcceptsTab = true;
            this.EditRichTextBox.Multiline = true;

            //Controls on the Form
        this.Controls.Add(this.ButtonCompilelib);
            this.Controls.Add(this.ButtonCompile);
            this.Controls.Add(this.ButtonRun);
            this.Controls.Add(this.EditRichTextBox);
            this.Controls.Add(this.ErrorTextBox);
        this.Controls.Add(this.chkBox);

        //CheckBox
        this.chkBox.Location = new Point(600,300);
            this.chkBox.Name = "chkBox";
            this.chkBox.Text = "Color";
        };

        //My checkbox handler
        this.chkBox.Click += (sender,e) =>
        {
            if(flag == 0)
            {
                flag = 1;
                MessageBox.Show("Coloring Text");
                }
            else 
                flag = 0;
        };

        //My TextBox handler
        this.EditRichTextBox.KeyPress += (sender,e) =>
        {
            try
            {
                string tmp = Environment.CurrentDirectory + "\\" + "mydll" + ".dll";            Assembly a = Assembly.LoadFrom(tmp);
                Type t = a.GetType("MyPlugIn.colorclass");
                MethodInfo mi = t.GetMethod("color");
                Object obj = Activator.CreateInstance(t);

                Object[] Params = new Object[5];
                Params[0] = EditRichTextBox.Text;
                Params[1] = EditRichTextBox.Handle;
                Params[2] = ErrorTextBox.Handle;
                Params[3] = EditRichTextBox;
                Params[4] = flag;
                mi.Invoke(obj, Params);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        };


        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new MainForm());
        }
    }
}

And this is the DLL file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace MyPlugIn
{
    public class colorclass
    {
        public void color(string Text, Object Hndl_Text, Object Hndl_Err, RichTextBox box,int flag)
        {
            if (flag == 1)
            {
                int start = box.TextLength;
                int end = box.TextLength;

                //Textbox may transform chars, so (end-start) != text.Length
                box.Select(start, end - start);
                {
                    box.SelectionColor = Color.Blue;
                }
                box.SelectionLength = 0; // clear
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:26:50+00:00Added an answer on June 17, 2026 at 12:26 am

    Yes, your code uses Reflection. These lines are an example:

    Type t = a.GetType("MyPlugIn.colorclass");
    MethodInfo mi = t.GetMethod("color");
    Object obj = Activator.CreateInstance(t);
    

    Whether is the best approach or not, or whether it’s necessary for this task, it’s a different topic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.