Using EM_CHARFROMPOS in custom text editor control without inheriting - c#

I am trying to develop a custom Text Editor Control and wish to use EM_CHARFROMPOS to find the character under the mouse cursor. This would be easy if I was inheriting from the RichTextBox or TextBox Controls however I wish to do all myself, not even trying to inherit from TextBoxBase.
Is there any way to do this, what data does this message operate on and can I use it?
Sorry no code, at the moment using Panel as my base.
Thanks Danny.

Related

Dashboard controls in Winforms

I am working on a WinForm based applications(Yes I don't know WPF) and want's a dashboard like panels in it. Picture given below
Each panel will have a title and records from Database and some action controls. How could this be achieved? I don't want to use GridControl as I don't want to show Excel like spreadsheet here. How could this be achieved?
It sounds like you want to make a UserControl, possibly coupled with an automatic layout panel like FlowLayoutPanel.
Simply speaking, you would create a UserControl with whatever properties and events you require (i.e. in your example you might have a Title property and a Data property), and any events you need to respond to (e.g. you might have a button that you provide a wrapper event for). Then you can add the control to your existing form as you would any other standard control.
As far as displaying data in list form goes, one suggestion is to use a Panel and dynamically add Labels to it. Another idea could be just a simple Label with line breaks in the Text.

create custom tooltip C#

I want to create a custom tooltip, with a different style so that when I click on a control (for example a label or a user-control) it appears.
Something similar to what Google does in Google Maps for coordinates.
I tried to create a user-control and show it when user clicked on a label, but it didn't work well.
It is WinForms!
I attached a picture of what I want. Thank you in advance!
Use a standard ToolTip but override the painting method so it can appear as you want it, while still behaving like a normal tool tip.
Haven't done this before so I can't provide an example.
EDIT: here is an example: http://cboard.cprogramming.com/csharp-programming/119414-custom-tooltip.html

Drawing custom TextBox Controls

I found this code here which explains how to create custom controls. I have been using these controls as buttons, but now that I am beginning to understand the code a bit more, I would like to try and create a text box control using the same drawing techniques. I have been searching endlessly for some examples on the subject, but cannot find a single one. I don't understand how a textbox can be writable if a rectangle is being used to make it. Does anybody have any experience creating custom controls in C#? I would like for my textbox to be able to match the theme in the above link which is why it has to be custom made.
Well, at the beginning you should have in mind, that the implementation of new text box control is kinda complicate thing. It is necessary that you consider the following points:
1) What should your textbox do? How can the user interact with it? Which events do you necessarely throw?
2) How should you textbox be drawn? Is it a simple box with an outline or do you have elements which are different if the user gets interacted.
A good starting point for implementing your own textbox is to look how it works under the hood - in fact, you should start by referencing to samples which came from the DirectX and DirectDrawing area, one example is the following link (the sample is for c++, but the concepts are the same as used in windowsforms or wpf drawing):
http://www.uc-forum.com/forum/d3d-tutorials-and-source/65377-make-textbox-ingame-console-directx.html
a more direct sample (explaining howto extend an existing textbox) can be found here:
http://www.codedblog.com/2007/09/17/owner-drawing-a-windowsforms-textbox/
All in all, to achieve your goal try to extend the basic text box at the beginning and afterwards start with a component which is not that complicated, for example a simple checkbox. Go on and at the end you will be able to implement your own textbox control ;)

richtextbox, embedding custom object

I have a customized class which holds every move in chess and I want to write down every move to a richtextbox. So I am going to overload the tostring() of that custom class and use some formatting to add it to the rtf property of richtextbox. I need to find out which object is clicked so that I can set the game board accordingly. I don't know how to detect which object is clicked inside the richtextbox. Probabely I can use LinkClicked event of the richtextbox by introducing every object as a link to richtextbox. Any ideas??
Not a direct answer of your question - but using a ListBox, ListView, or other list control is not only much simpler, but will do everything you are asking and more (it's what they were designed for).

WPF (irc) chat log control

I'm trying to learn WPF and was thinking about creating a simple IRC client. The most complicated part is to create the chat log. I want it to look more or less like the one in mIRC:
or irssi:
The important parts are that the text should be selectable, lines should wrap and it should be able to handle quite large logs.
The alternatives that I can come up with are:
StackPanel inside a ScrollViewer where each line is a row
ListView, since that seems more suitable for dynamic content/data binding.
Create an own control that does the rendering on its own.
Is there any WPF guru out there that has some ideas on which direction to take and where to start?
I suggest you start with a good object model independent of the UI, and then try a multi-line TextBox or a RichTextBox.
Whether these will suffice will depend on exactly how long you want the log to be able to get. If you run into performance issues, you may need to look at virtualization.
First of all, you should consider if you want to select only entire row (like in a listbox), or if you want to select certain characters from a row (like in a textbox).
In the first case, I think a ListView or even a ListBox should be enough, both of them support virtualization when bound to collection and there should be no problem with huge amounts of data. A stack panel inside a ScrollViewer is a little bit like reinventing the wheel for this case and creating a new control is not a very inspired approach in my opinion (as the functionality you want can be achieved with the existing controls, in WPF).
In the second case, if you want to select some text inside of a line, or if you want word wrapping for your longest lines in the log and want to select individual parts of the wrapped lines, then you need to use a control more oriented on displaying text. Kent already suggested a RichTextBox, I would add AvalonEdit control or even the WebBrowser control in which you directly modify its HTMLDocument.
I would suggest to use RichTextBox too, and store items in a log file or database, if you run into performance issues.
Another solution is to use the WPF WebBrowser control and modifiy its HTML content with:
webBrowser.NavigateToString("<HTML><H2><B>This page comes using String</B><P></P></H2></HTML>");
More information about using WebBrowser control

Categories