I have an application on windows with multiline text field on it. I need a way to draw lines on that text field, so you could see both, the letters typed and those lines. I need to do this with C#, but I can use .dll's written in C++.
I've heard something about subclassing where I could overtake render function from a window and adjust something to it, how do I do that with C#?
Or maybe there are simplier ways than that? Please share.
In .NET Framework, you may use WPF and write user control with Canvas and TextBox overlaying - and then make such operations with Dependency Properties tracking
Related
I had some little experience in coding, but I am absolute beginner in C#. In my program I want to make the text visible in form, sort of like in HxD program. I don't want it to be standard editable text, but a monospaced text which can be selected, and if selected there would be yellowish (but with no border) background in back of it, I have no idea how to do this, if even possible with standard controls. How can I implement this? Do I need to use some external library? I want also to mention that I want spaces between characters and lines to be configurable.
I am using Visual Studio C# 2015.
Here is mock-up:
I've done similar before using a RichTextBox that wasn't editable by users. It has more functions for manipulating just part of the string than TextBox does.
This is a broad question, I am aware. However, I have been trying to make a modification in a C# source code to enable a ToolboxControl UI control's right hand border to respond to a mouse drag. In other words make the control size bigger by grabbing the right hand boarder and dragging it to the right. I Have not been successful. So I am thinking if I incorporate a XAML file and create the ToolboxControl in XAML, maybe I would have more control in manipulating the ToolBoxControl.
I dont know how to break up a pure C# WPF code into C# and XAML.
In a nutshell, The problem I am dealing currently is that there is already C# code developed by other developers to perform certain function. I am using the existing C# code but I believe if I move some of the UI functionality from the C# into a XAML file, I would have a better handle on adding some of the needed UI features to the original program.
So you see my problem is I am not starting from scratch. I need to use an existing C# code and break away some UI functionality of it nd put it in a new xaml file. Do you have any ideas about any place that that has been done?
I am looking for any repsonse that leads me to a conversation thread or a sample. In other words I dont know where to start from. any useful guidance is apprecaited and would be marked as an answer.
Check out this article.
At its simplest, you will need to add an invisible (or not) drag handle to the right hand border of your control, then adjust the control size during the drag events raised by that drag handle.
Here is another article showing a similar concept expanded to an entire diagramming system, which includes the resize behavior you mentioned.
You may be able to define a style for what you are trying to accomplish. I wouldn't worry too much about breaking apart the C# from the XAML as that is a nice to have but not nec
May be i can get some negative points on this question but, really this question is boggling in my mind from last many days that what is the basic/raw code behind textbox(or other such controls).
i mean i understands that, we can inherit the textbox class and make our changes, we creates its object and use it.
but wants to know how that class creates a textbox(the design which allow us to enter text) (same query for other components), is it a code of 'C' language which are generating it using CG (computer graphics) programming or any other thing.
Experts please resolve my curiosity.
Thanks
Windows provides several basic API's for drawing on the screen. You can draw pixels, lines, boxes and more complex geometric shapes. There are also API's to draw text. Other API's allow you to react to user input, e.g. mouse movement and clicks and keyboard input.
From these basic API's you can create your own text box by drawing the exact pixels of how the text box should look and react to user input. However, Windows has a built-in concept of a text box. This text box has a standard look and feel and is also integrated with UI concepts like focus, tab order, the clipboard and the caret. But behind the scenes Windows is using the low level API functions to draw on the screen and react to user input.
When you create a TextBox in Windows Forms it actually creates and wraps a standard Windows Edit control. This control is drawn using GDI. However, other programming models like WPF may create TextBox controls that looks like a normal text box but uses a custom implementation supplied by WPF and is drawn using DirectX.
Use http://www.red-gate.com/products/reflector/ and see for yourself...
Here is what I think it is doing:
The Raw code behind TextBox or any other Control uses Windows API that is responsible for drawing these controls and provide Handles of these controls for later reference.
Windows has been using different methods to draw it's UI like GDI, GDI+ and sometimes DirectX. I may be wrong and there may be some other techs I forgot to mention.
These controls use each window's WinProc to receive Input Notification and other callbacks that notify these controls when clicked, typed or for example resized.
I'm tinkering with writing a simple text-based role-playing game. I would like to use WinForms, and utilize WinForm controls for the UI and simple text for the output. The catch is, I would like to have complete control over the formatting of the individual text - some words being different colors, etc. A simple console control would suffice, as that would provide control over text colors, but it would be nice to also be able to change style, font and size.
Less important: it would be nice to have complete control over where text appears in the control through a coordinate system, as with DOS windows of old.
I'd appreciate suggestions on the best method of implementing this. Perhaps there is a better method I had not considered for rendering the output of a text-based game.
Hmm... maybe you could use or adapt a RichTextBox or a WebBrowser control for this purpose?
You have complete control by overriding the OnPaint() method. Use TextRenderer.DrawText() to get it exactly the way you want it.
Background:
I'm going to start studying/coding at the local university's library. Since I'm not a student, I won't be able to utilize their wireless internet access. Since StackOverflow is such a great resource, I want to be able to take it with me, so I'm building a small desktop application to load/search/display the most recent data dumps.
Problem:
I want to display code blocks in the same sort of rectangular block as this site does, so I played with the RichTextBox control to try to create this effect. Unfortunately, the RichTextBox.SelectedBackColor property only colors the actual text, when what I want is a rectangle reaching to the outer limits of the selection.
Example:
This is what I am able to produce with the RichTextBox:
This is what I would like to create:
Questions:
Is there any way to produce this effect using the RichTextBox?
If not, are there any other controls I could use to create this effect?
I don't think so, there is no mention of controlling this behavior on MSDN.