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

  • Home
  • SEARCH
  • 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 3985218
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:51:49+00:00 2026-05-20T05:51:49+00:00

Is it possible to draw overlapping semi-transparent (with a low alpha value) which will

  • 0

Is it possible to draw overlapping semi-transparent (with a low alpha value) which will not accumulate the alpha values? When I do it now, if in the overlapping area I have a rectangle with alpha of 50, the alpha value of the overlapping area will be 100.

Here’s a sample program which demonstrate the problem.
I added a button which draws the rectangle in the same place and that increases the alpha value.

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

namespace Sample {
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            richerTextBox1.MarkLine();
        }
    }


    public partial class RicherTextBox : RichTextBox
    {
        private const int WM_PAINT = 0x000F;
        private const int WM_VSCROLL = 277;
        private Graphics m_graphics = null;

        public void MarkLine()
        {
            if (m_graphics == null)
                m_graphics = this.CreateGraphics();

            int firstCharOfLine = this.GetFirstCharIndexFromLine(0);
            Rectangle marker = new Rectangle(0, 0, ClientSize.Width - 1, this.Font.Height);
            m_graphics.FillRectangle(new SolidBrush(Color.FromArgb(60, Color.Red)), marker);

        }

        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_PAINT:
                    MarkLine();
                    break;
                case WM_VSCROLL:
                    MarkLine();
                    break;
            }

            base.WndProc(ref m);
        }
    } }

and the designer:

namespace Sample
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.richerTextBox1 = new Sample.RicherTextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // richerTextBox1
            // 
            this.richerTextBox1.Location = new System.Drawing.Point(22, 12);
            this.richerTextBox1.Name = "richerTextBox1";
            this.richerTextBox1.Size = new System.Drawing.Size(239, 183);
            this.richerTextBox1.TabIndex = 1;
            this.richerTextBox1.Text = "";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(168, 210);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(76, 26);
            this.button1.TabIndex = 2;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.richerTextBox1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }
        #endregion

        private RicherTextBox richerTextBox1;
        private System.Windows.Forms.Button button1;
    }
}
  • 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-05-20T05:51:50+00:00Added an answer on May 20, 2026 at 5:51 am

    You cannot paint with transparency to a windows control this way. Compositing can only happen between BeginPaint and EndPaint (or on a DC created from a bitmap).

    Attempting to customizing the Windows rich text control is possible, but in the end always ends badly. That is why there are so many 3rd party text editing controls out there.

    My suggestion is that you ask a different question, “How do I draw the background of a line on a RichTextBox in a different color?”

    Or get a 3rd party text editor which will give you this feature and many, many more.

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

Sidebar

Related Questions

is it possible to draw a line semi-transparent with image magick? i want to
It is possible to draw markers in runtime or at onLocationChange event, not on
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Is possible to draw a quad given its normal vector, a point that is
Is it possible to draw a line using a graduated colour? I want to
Is it possible to draw a 3D chart using JfreeChart like in the following
Is it possible to draw curved lines in an HTML page (normally across cells
Is it possible to draw a road using bing maps js api? Ideally I
How is it possible to draw an overlay over an game with DirectX 9

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.