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 8026829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:36:54+00:00 2026-06-04T23:36:54+00:00

Is it possible to create a transparent messagebox (rectangle) that can write multiple-line text

  • 0

Is it possible to create a transparent messagebox (rectangle) that can write multiple-line text on it?

  • 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-04T23:36:54+00:00Added an answer on June 4, 2026 at 11:36 pm

    Andy’s solution will suffice, but it might take a few tries until you find the transparency you’re after and it also involves creating and loading a new resource in your program. Fortunately you can avoid this and can make the process configurable by generating a single transparent pixel at runtime which will stretch to the bounds of the Rectangle argument in the SpriteBatch.Draw(Texture2D, Rectangle, Nullable<Rectangle>, Color) call:

    //You can probably turn this in to a re-useable method
    Byte transparency_amount = 100; //0 transparent; 255 opaque
    Texture2D texture = new Texture2D(Device,1,1,false,SurfaceFormat.Color);
    Color[] c = new Color[1];
    c[0] = Color.FromNonPreMultiplied(255,255,255,transparency_amount);
    texture.SetData<Color>(c);
    

    Now use the new texture variable in your draw call.

    As for multi-line text, there is a SpriteBatch.DrawString() overload that accepts a StringBuilder argument. Meaning you can in theory go:

    //configure
    StringBuilder sb = new StringBuilder();
    sb.AppendLine("First line of text");
    sb.AppendLine("Second line of text");
    
    //draw
    SpriteBatch.DrawString(font, sb, position, Color.White);
    

    I’ll give you another hint that will help you determine the size of the drawing rectangle for the texture:

    //spits out a vector2 *size* of the multiline text
    Vector2 measurements = font.MeasureString(sb); //works with StringBuilder
    

    You can then create a Rectangle from this information, and even give it some padding:

    Rectangle rectangle = new Rectangle(window_x, window_y, (int)measurements.X, (int)measurements.Y);
    rectangle.Inflate(5); //pad by 5 pixels
    

    Then put everything in to the draw call, including what color to draw the window

    SpriteBatch.Draw (texture, rectangle, Color.Black); //draw window first
    SpriteBatch.DrawString(font, sb, position, Color.GreenYellow); //draw text second
    

    The result is a little nicer looking, more automated, and configurable. You should be able to wrap all this stuff in to a re-usable configurable class for your notification messages.

    Note: anything other than drawing code should be in LoadContent() or somewhere else, not the actual game’s Draw() call.

    Pardon any syntactical errors, I’ve just wrote it off the top of my head.. 🙂

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

Sidebar

Related Questions

I want to create a c# application with multiple windows that are all transparent
Is it possible to create a form that is semi transparent, It should be
Is it possible that I can create a margin/padding between the background image and
Possible Duplicate: Create shortcut to console.log() In javascript we can easy assign functions to
Possible Duplicate: create multiple variables based on an int count Objective C Equivalent of
Is it possible to create an object that is @RooSolrSearchable without being a JPA
Is it possible to create partially transparent elements on the fly in canvas? Currently
is it possible to draw a line semi-transparent with image magick? i want to
Is it possible to create transparent corners for an image on fly with PHP?
I am using RGBA to create a transparent background that overlays on top of

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.