Hello folks. I'm writing a Roguelike game in C#. Fun stuff. The game
includes a map that is made entirely of colored ASCII art in a
monospace font. I would like to make this map a control in the main
form.
My first attempt was with RichTextBox. I wanted to set the background
to black. After cruising newsgroups I determined that wasn't possible.
My second attempt involves an AxSHDocVw.AxWeb Browser control. I got
this by adding the "Microsoft Web Browser" control to my Toolbox. This
control does not play nicely with the rest of my form! It constantly
steals focus for itself, and there isn't a reliable mechanism for
forcing my main form to have focus. Since that control is not set up
to handle keyboard events (this is how the player moves through the
map) other people on newsgroups have been told to write an unmanaged
DLL that snags a (global?) hook and signals my application when
keyboard input has been entered.
That seems awfully complicated. A wise software engineer once told me
when a solution seems inordinately complex that I should ask if there's
a better solution. So that's the purpose of my message. :) I want to
display multicolored text in a form control. I want to be able to
change the background as well as the foreground, and I want to be able
to acquire keyboard input without writing a bunch of low level code.
What is the best solution? What is the best control to use? I am
using .NET 1.0.
Thanks! 7 2465
Er, why the insistence on using a character-based control?
It'll be much easier and more flexible to use some blank generic
control (like a Panel) and do the text rendering with
e.Graphics.Draw String within that control's Paint event.
Eq.
Why it is not possible to set the RichTextBox bg to black ?
Your first attempt was the correct one. Set the BackgroundColor of the
RichTextBox to black. You can then set the color of any text by using the
SelectionColor property when adding the text.
Set the SelectionColor property and then use AppendText to add some text in
that color. Reset the SelectionColor property and use AppendText to add some
more text in the new color. Etc.
--
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
The man who questions opinions is wise.
The man who quarrels with facts is a fool.
<Ch************ ***@gmail.com> wrote in message
news:11******** **************@ 38g2000cwa.goog legroups.com... Hello folks. I'm writing a Roguelike game in C#. Fun stuff. The game includes a map that is made entirely of colored ASCII art in a monospace font. I would like to make this map a control in the main form.
My first attempt was with RichTextBox. I wanted to set the background to black. After cruising newsgroups I determined that wasn't possible.
My second attempt involves an AxSHDocVw.AxWeb Browser control. I got this by adding the "Microsoft Web Browser" control to my Toolbox. This control does not play nicely with the rest of my form! It constantly steals focus for itself, and there isn't a reliable mechanism for forcing my main form to have focus. Since that control is not set up to handle keyboard events (this is how the player moves through the map) other people on newsgroups have been told to write an unmanaged DLL that snags a (global?) hook and signals my application when keyboard input has been entered.
That seems awfully complicated. A wise software engineer once told me when a solution seems inordinately complex that I should ask if there's a better solution. So that's the purpose of my message. :) I want to display multicolored text in a form control. I want to be able to change the background as well as the foreground, and I want to be able to acquire keyboard input without writing a bunch of low level code. What is the best solution? What is the best control to use? I am using .NET 1.0.
Thanks!
Thanks to all for responding.
Paul - that's an interesting solution, one I didn't know was possible.
I'll play around with it.
Tasos, Kevin - I forgot to mention that I have the RichTextBox's
Enabled property set to false. This is what causes the control's
background to always be gray. Even if you set it after
InitializeCompo nent()! If The Enabled property is true, then an
annoying cursor shows up. Is there a way to force an non-Enabled
RichTextBox's background color to be black instead of gray? Another
possible solution: is there a way to get rid of the cursor? Setting
the control's ReadOnly Property to True does not appear to work.
Thanks again. Ch************* **@gmail.com wrote: Paul - that's an interesting solution, one I didn't know was possible. I'll play around with it.
If you have trouble getting it to work, you can mail me and I'll try
to send you an example. It should be much easier to do things like
scrolling if you have total control over what gets painted.
Tasos, Kevin - I forgot to mention that I have the RichTextBox's Enabled property set to false. This is what causes the control's background to always be gray.
Well, if you really want to use a RichTextBox, you could leave it
enabled but handle the KeyPress (and similar) events with special code
to prevent selections, deletions, insertions, and so on.
Eq.
Chris,
Have you tried inheriting from the RichTextBox class, and overriding the
OnPaintBackgrou nd method?
That should let you set the background colour to whatever you want.
Paul Ch************* **@gmail.com wrote: Thanks to all for responding.
Paul - that's an interesting solution, one I didn't know was possible. I'll play around with it.
Tasos, Kevin - I forgot to mention that I have the RichTextBox's Enabled property set to false. This is what causes the control's background to always be gray. Even if you set it after InitializeCompo nent()! If The Enabled property is true, then an annoying cursor shows up. Is there a way to force an non-Enabled RichTextBox's background color to be black instead of gray? Another possible solution: is there a way to get rid of the cursor? Setting the control's ReadOnly Property to True does not appear to work.
Thanks again.
Thanks Paul. I extended RichTextBox into a new class called
MapDisplayTextB ox. The default constructor calls the base contructor.
Afterwards it sets Enabled to false (so that there is no carat) and
BackColor to Color.Black. Unfortunately this has not worked. I double
checked that I'm instantiating a MapDisplayTextB ox instead of a
RichTextBox. I also extended some other methods to experiment and
investigate.
Here's my class:
public class MapDisplayTextB ox : System.Windows. Forms.RichTextB ox
{
public MapDisplayTextB ox() : base()
{
this.Enabled = false;
this.BackColor = Color.Black;
}
protected override void OnPaintBackgrou nd(PaintEventAr gs pevent)
{ MessageBox.Show ( "OnPaintBackgro und called, color is " +
this.BackColor. ToString() ); }
protected override void OnBackColorChan ged(EventArgs e)
{ MessageBox.Show ( "OnBackColorCha nged called, color is " +
this.BackColor. ToString() ); }
protected override void OnPaint(PaintEv entArgs e)
{ MessageBox.Show ( "OnPaint called, color is " +
this.BackColor. ToString() ); }
}
When the exe is invoked, I get one messagebox that indicates
OnBackColorChan ged was called and the color is [Black]. However when
the form is displayed the background is gray.
Maybe there is some kind of behavior coded somewhere else for
nonEnabled forms? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shawn Hogan |
last post by:
I'm looking for a control that supports multicolored tree view nodes. I want
to have a string of text consisting of 3 pieces displayed in three different
colors per node. Imagine how IE displays XML withj multiple colors per node.
I've looked at a few options... the best thus far is TList that displays RTF
as the node text. Are there any other controls that display RTF as node
text?
Thanks for any suggestions,
Shawn
|
by: Yoshitha |
last post by:
hi
I have datalist control in my ASP.NET application
the problem here is
i have used a textbox with multiline true propertly when i enter data like
"fdjsfhjksdhfjsdfhsdjhfsdfhsdjfhsd
jfdsjfksdjfksdjkfjsdfjksdjfsdjfd
fdsfhjsdhfjsdhfjf dsjf dsjfhjsdfhjksdh d fdsjf
hsdjkfhdjsfhsdjfh ds
|
by: Susan Bricker |
last post by:
Greetings!
Still the same application (as previous posts). I worked on the app
while at work (don't tell my boss ... cause this is just for fun and not
work related) and the form was working, but now when I try to repeat the
code at home (for real) it won't work. I suspect that I haven't
replicated the logic and forms at home from what I remember that I did
while at work.
My subform is based on a table called "tblTrialClass" and it...
|
by: Tomaz Koritnik |
last post by:
Hi
I have many short HTML files stored in a binary stream storage to display
descriptions for various items in application. HTML would be display inside
application using some .NET control or COM control (like Microsoft
WebBrowser). For each description there is one HTML file and along
description text, it contains links to related information. Clicking related
information would for example open new form in application and display some...
|
by: Earl Teigrob |
last post by:
I can create a new custom control (and not change it) and add it to the
toolbox and drag it onto the disign screen and it works just fine,
displaying the text . However, when I add the following
datepicker control to the toolbox, it just shows a yellow dot and thats it.
What happened to the text???
Earl
| |
by: RAJ |
last post by:
In our multi-tier application, we have several ASP.NET user controls which
will update the same data source provided by middle tier logic.
In this particular scenario we have one user control displaying the contents
of the data source, whilst another control updates the datasource via a
command buttons implementation of 'Click', an event raised in the 'Handle
Postback Events' stage of the control execution life cycle (via the...
|
by: gnewsgroup |
last post by:
I've googled and tried various approaches, but could not resolve this
problem. The article at MSDN: Displaying Images in a GridView Column
only presents a simple case where all data (including the images) of
the gridview come from a single table/datasource.
Here is my situation. In my web application, I need to display
customer bills info in a gridview.
Customer names and contact info are from the Customer table.
|
by: Stuti |
last post by:
Hi,
I need a text box control which can accept multi colored texts and can also support auto complete feature. I took a look at the richtextbox control which takes multi-colored text but it has no support for auto complete feature.
I also searched for any relevant control in infragistics and syncfusion but no help !
Has anybody ever designed such a text box?
I dont have much time so can't go for writing a customized text box for...
|
by: RichB |
last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am
trying to add a tabbed control to the page.
I have no problems within the aspx file, and can dynamically manipulate a
tabcontainer which has 1 panel already, however I want to try create the
TabPanels dynamically. I followed the advice here:
http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe
Stagner)
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |