I am wondering if anyone has any experience in creating a new control based on a WPF text box that could support syntax highlighting, line numbers, etc.
Any links or advice on how i could begin creating something like this would be very helpful.
Hey there. I don't have any personal experience implementing something like you're suggesting, but I found a couple of links that might help you out.
Derived rich text box with syntax highlighting
SharpDevelop (it's open source and you can probably grab some insights from their source code for syntax highlighting)
Syntax highlighting in a Coacoa app (maybe glean some approaches from this)
This should help you to start WPF Syntax Highlighting in RichTextBox
Related
I am working in a wpf project in which I need to compare two strings and display in a side by side window with line number should be shown and differences must be highlighted with color.
I am new to wpf and I don't have any idea about completing this task.
Please help me.
Are you looking at something like Syntax Highlighting of Text after comparison(or identifying the differences)? Below links might help you if you want to do simple highlighting of the text. The idea should be simple perhaps:
Identify the Difference
Find the start and end position of difference
Highlight the difference only.
If you'd want to go for simple solution, check these link if they work for u:
https://code.msdn.microsoft.com/windowsdesktop/CSWPFSearchAndHighlightText-3b5e207a
https://social.msdn.microsoft.com/Forums/vstudio/en-US/7c9a622a-4e3b-451e-bc4c-ab9d011447e0/texthighlighting-in-wpf-richtextbox?forum=wpf
Moreover, there are several controls available online for Syntax Highlighting in wpf. You can simply search for it. I came across Fast Colored TextBox on CodeProject once for similar requirement. Hope this helps.
I think this would be the generic advise I might be able to offer for a generic question like this. Or u may want to go a bit more specific about what type of content you are trying to highlight? Is it Rich text or plain text in a TextBlock? And as the comment above? Any research & considerations you've done? And any code to give an idea about the scenario?
Please forgive any silly words I may say. I am coming from a Actionscript3 background.
I am using "Visual C# 2010 Express".
I have a simple Form, in a WindowsForm Project, which currently holds just a Listbox. (Which I presume I will have to change to something else).
And I made myself a different display object (User Control) that is currently a Checkbox a title. (More will be added once I get over the hurdle below)
But I can't even get as far as Displaying the UserControl as a list.
I can't seem to find anywhere on the listbox to say "User this displayobject as the visual for listbox". I see tutorials saying "ItemsPanelTemplate" but I get error saying there is no such property for a Listbox.
I even tried making the Form in Design view and it is not in the list down the side of the GUI when I dragged as Listbox on screen.
Now I know how I would do this in pure Actionscript, but I dont know how to do this in Pure C#. Tutorials are not helping, as all the Microsoft site seems to try to give me is XAML (XML). and I am looking for C# code. So I have thrown in the towel and pleading for outside help.
Thank you for any help you can give.
It sounds like you want a list of items, each with a CheckBox and some descriptive text. Try using the CheckedListBox control. MSDN link.
This question also answers the question of how to do custom image drawing for each item in a ListBox. It may be helpful.
Edit after clarification:
Try embedding the UserControl in a ListView, rather than a ListBox.
References on embedding controls in ListViews:
C# listview - embedding controls
Adding button into a Listview in WinForms
You could also use a list of Panels, with each Panel hosting a UserControl.
C# List of Panels
But the real answer, as seen in the question's comments, is that Winforms doesn't have a convenient way to do this. This is a task much better suited to WPF.
You may check out freeware component Better ListView Express from ComponentOwl. It supports simple Details view without columns, two and three-state checkboxes, images and more...
They also offers full version with even more nice features like hierarchical and multi-line items.
I'm newbie for Windows phone 7 development.
Usually the User interface Design is done with a Designer and Drag & Drop. But In my project I have to code all user interface programmatically, that is manually write design controls in .Cs file instead of .xaml file.
Is it possible? I have tried googling it, I haven't found any tutorial or documentation yet.
Could someone please help me to start my process.refer some documentation or books
Thanks
I definitely think you can do everything without XAML if you want to.
The basic approach should be to create a basic app with App.xaml and an almost empty Page.xaml. After this you should be able to dynamically add controls to meet your needs.
The majority of this work is quite straight-forward
creating controls, setting properties, adding event handlers are all easy.
The more awkward things will be things like producing animations, visual states, styles and databindings - the XAML syntax for these is quite convenient compared to the C#
Also, if you need multiple pages, then using navigation is also a bit more awkward - the NavigationService is currently built around XAML-based pages.
In iron7, I've written lots of single page apps without using XAML. All the code is in IronRuby rather than C#. As a developer, I think you should be able to follow most of them - take a look at these examples on script.iron7.com:
create a UI with some text boxes and some buttons
a calculator with animations
fingerpaint - canvas and "mouse" touch
panorama control and pivot control
Tetris
To run these scripts just download iron7free from the marketplace. To convert them back into C# is mainly a case of removing some "_" characters, modifying some capitalization and turning def's into C# methods.
Note - for clarification, I am not recommending you write your app in Ruby - it's just that these are the only examples I have of writing an app in code instead of XAML.
You have to create a basic xaml page first with at least a stack panel on it.
Then you can add controls to your stack panel like this
TextBox textbox = new Textbox();
textbox.Text = "TEST";
PageStackPanel.Children.Add(textBox);
You do have drag and drop ability for the Windows Phone 7 development. Download the Visual Studio for Windows Phone 7 and try the samples. http://www.microsoft.com/express/Phone/
Here is a tutorial for the starters:
http://blogs.msdn.com/b/somasegar/archive/2010/03/15/introducing-windows-phone-7-development-tools.aspx
Well its the Silverlight framework. You can code it by hand using XAML (eXtensible Application Markup Language)
Charles Petzold is writing a book on Windows Phone 7 programming, you can download it free here:
http://www.charlespetzold.com/
Generally I don't like the designer and try to avoid it as much as possible. I find writing Xaml easier.
But I also try to avoid the use of Xaml because:
Performance: the C# code is definitely faster
Programming style: I hate when the related code is scattered over several files. It's not only my C# code, but also hidden auto-generated code (sometimes containing unnecessary constructs).
Debugging: Xaml allows for more bugs (e.g. incorrect spelling), Xaml bugs are more difficult to localize
Having said that, I have to disagree with Stuart: Certain things cannot be done in C#, you need to do them in Xaml. For example:
Visual states: You cannot set readonly property VisualStateGroup.Name in C#, but you can use x:Name attribute in Xaml.
UserControl.Content is protected (for SVL3 and thus also for WP7), but Xaml bypasses this limitation
Etc. (There are more such special things.)
how i integrate html text editor in windows application?
The best option would be to use a commercial syntax highlighting package, such as Actipro SyntaxEditor.
You can just use a RichTextBox and do it yourself, but it is going to be more difficult to make this seem polished. There are some articles, such as the CodeProject article, which show how to extend RichTextBox for custom editing and coloring. That would be a good starting point, if you want to make your own.
If you just want a place people can type HTML in, but don't need coloring, syntax checking, etc - you can just use a RichTextBox and let the user type in the HTML.
I need to create a text editing control in C# and I'm not sure where to start.
For a bit of context: a C# program is going to edit an XML document (using this control). The XML document can be converted to HTML.
The XML document will contain the following:
Normal text (obviously)
Headings (which will be formatted differently)
Lists
Images
Videos (they don't need to be viewed in the control, but there needs to be a box or something to indicate that they're there)
I want this control to take the XML and render it and act as an WYSIWYG editor for the XML.
For the moment, I'm not to concerned about implementing all the above details (although they will need to be implemented eventually), I just want to know where to start with creating this control. Should I be inheriting from TextBoxBase (or TextBox) and going from there? And what methods would I need to override? Or should I inherit from Control (in which case I think I'd need to all the text box stuff - selecting text, copy and paste, the caret etc. - myself, which is something I don't really want to do, but I am prepared to do if I have to).
I am aware of preexisting controls like TX Text Control that do something like what I want (although this one is far more powerful than I need), but I can't use these (this is for a university project), and besides, I really do want to know how to make this from scratch.
The topic of creating a feature rich edition control with syntax highlighting, code completion, etc. has been discussed by the developers of #develop in their book "dissecting a C# Application"
http://www.icsharpcode.net/OpenSource/SD/InsideSharpDevelop.aspx
(I think you can't buy it anymore, the link says it's available for free to download but the links seems to be broken)
The book basically explain the core features of #develop (pre V1, so it's kinda outdated), including the code editor and (what is important, too) which mistakes they made during the process.
Should I be inheriting from TextBoxBase (or TextBox) and going from there?
You can't inherit from TextBoxBase (its constructor is internal).
So you can inherit from TextBox or from Control or UserControl.
The problem with TextBox is that its painting is done by unmanaged code, which isn't overridden when you override OnPaint. For further details, see this question, answer and comments.
I am aware of preexisting controls like TX Text Control that do something like what I want
The TX Text Control is something else: it's implemented using Win32 code, with a .NET wrapper/API.
A few years ago I used the excellent open source Scintilla editor as a base to derive a custom C# control from. Worked great. Nowadays it's even easier if you leverage the ScintellaNET project (CodePlex) which has already done the wrapper work for you. Of course, if you don't mind paying, you can't go wrong with Actipro's SyntaxEditor.
Inheriting from Control will require lots of work, such as painting, implementing default behaviour, etc..
I think you can start with studying RichTextBox control because all of your requirements can be done by changing RichtextBox control.