Do You know any good example or any good hint on how to make user controll that has defined text with blank areas which has to be filled out to complete excercise. Then submit answer and check (what was written in blanks and check if its good or not).
What Is the best way of doing that in order to be quite generic for example user (teacher) marks text which should be hidden.
It may be in WPF or WinForms (whatever is better for that).
thanks for any hint on how to begin and what to use.
I think I would have a (WPF) UserControl derived class that can take a custom formatted string (or xml) that contains the text and the placeholders to display:
myUserControl.DisplayContent="Rome was built in #numberofdays# day(s). The first mayor of Rome was #mayorofrome#."
The UserControl parses that string and builds the UI consisting of TextBlocks (the static text) and TextBoxes (the input controls).
Additionally the UserControl has a Property of Type Dictionary<string,string> that contain the strings entered by the user (keyed by placeholder string):
Console.WriteLine(myUserControl.Result["numberofdays"]);
Console.WriteLine(myUserControl.Result["mayorofrome"]);
This dictionary will be filled by the UserControl as the user enters the texts.
Related
I am new here and startig to learn C#. Before I programed in C and Windows.Forms in VBA.
Now I have a Project where I receive serial port data from a device, that sends the contents of various C-structs (some nested). I want to display these Datasets in Windows.Forms each labeled, edit the values and send it back to the device. So it can easily copy the received data into its structures.
Now I don't know an easy way to get the structured data inside a c#-byte-list into various text boxes(?) that have describing labels to it. I would like to design the layout in Form Designer, so not want to create the controls dynamically. But maybe this is the best way?
Does someone know a good strategy / a best suited control to achieve this?
Thanks in advance.
You could use a DataGridView with control buttons inside each row or external buttons that handle selected row(s). In order to see and change the details a corresponding dialog form comes in handy in which I would implement a hex editor with the byte/hex values on the left and the readable value on the right.
To display the byte data just convert it to a hexadecimal string so you can display it in one column inside the DataGridView.
For the nesting part, you could either implement child elements inside the DataGridView itself (you need to either code this yourself or use some 3rd party extensions like this or Telerik, e.g., which also has the possibility of including button columns) or open a conditional dialog form which again shows a DataGridView for the child elements and so on (so you would open the same form as child form ad infinitum).
Thereby you are as flexible as possible and do not rely on fixed text box elements which you have to add or extend on further information.
I am using Visual Studio 2019 in order to create a Windows Form Application. I need some titles in my application, which means these strings will not be modified by the user.
For now, I created textboxes for these titles and made these textboxes "read-only". However, this does not satisfy my aesthetical expectations.
Therefore, I wonder if there is a way to add a string without adding a textbox, to the form. Is there a way?
Thanks in advance :)
Consider using a Label control rather than a TextBox.
The only time I would use a TextBox as a label is if I want the user to be able to copy the info, and I make it borderless, readonly and have the same colour as the background of the form. It's not superb UX though as there isn't anything that screams "you can highlight and copy this text" other than an I beam cursor, which is pretty much "mystery meat navigation" - better off putting a copy button next to it if you expect the user to copy info often
Why not use Label for your titles?
Since label, by default, cannot be modified by the user, thats what you want. Textbox is used for the user input, not for the titles.
Use Label control that is the right control to use for your requirement
I have written a winform application where i have a form with richtextbox control populated with string. I need to search specific pattern of string from the the string in the richtextbox control when user presses ctr+F just like we Find specific pattern of string in notepad++. Do i need to create the Find window by myself or is there any default Find window control which I can use?
Any help is highly appreciated.
You have to create a window that finds the specific character/word or sentence what you want. Windows Form Control doesn't provide any kind of UI facility to find your string. It is also depends on that from where you want to find the string. you must have an editor like Textbox, RichTextbox or any control which contains string values like DataGridView, WebBrowser Control, ListView etc. but, each control can have their own method to find a specific string. for example if you want to find a string in RichTextBox then you have to call the method from that particular control (richTextBox1.Find(...)). You can't find the string from all controls globally.
If you want to implement the feature in particular control like TextEditor (Word Pad) then there is an example on Code Project site that you can refer.
RichTextBox Control with Find functionality
at the moment I'm trying to get into Windows Store App Development and I'm stuck at some point.
I want to implement sort of a "markdown language" like the one on stackoverflow to highlight certain parts of text input.
Besides that I want to give the user the ability to use different font colors on his text.
The RichEditBox seems to be the ideal control for this task, but I don't know how to detect markup entering on the fly.
For example when the user enters **Test** the text should be transformed to Test immediately.
I have tried to approach this by listening to the "TextChanged" event and looking if the user enters **. If this is the case and if he entered the sequence ** already one time before, then I'm setting the character format of the text range from the end of the first annotation sequence (start marker) to the beginning of the second (close marker) annotation to bold.
But this solutions seems to be very quick and dirty.
My second thought was to use the WebView control to render the text after preprocessing it with "Markdown Sharp".
But then the user won't be able to edit text.
So I need to get some advice or tip on approaching this problem. I also looked into writing a custom RichEditBox control, but I have no experience in custom control development and there aren't that many resources on the web for Windows 8 development for now.
Thanks in advance.
As I see it, your problem is that you want to edit the "source" based on Markdown syntax AND show the formatted result in the same place. How would you revert Test to regular, as long as the asterisks are gone? If the answer is "using a button" then why not use the button to make it bold in first place?
However, you could do a hybrid thing: apply formatting in the source text, while maintaining the Markdown markup (not sure if this is entirely doable for all Markdown tricks, though). That is, **Test** would look in the source like **Test**. For the final, formatted result you would use a separate view, such as RichTextBlock.
In order to do the hybrid formatting, an option would be to have a background thread matching regularly the whole text against regular expressions specific to the Markdown syntax. For each match the corresponding text range would then be formatted accordingly.
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 ;)