I'm working on a windows forms application that reads and displays source code files from my hard drive. I'm not sure which control would be best suited for this. Is there any library that will allow me to display the source code with colors and numbered code-lines?
EDIT: To clarify, what i'm looking for is a way to display the code with colors and line-numbers, no need for editing. The application is to be used by a teacher, allowing him to view source code files handed in by his students. The teacher doesn't have to be able to edit the files.
ScintillaNet is a WinForms control which is a .NET wrapper of the excellent Scintilla library and is quite good. Avalon which is mentioned in another answer is also very good, but it is an WPF control (of course, WPF controls can be added to WinForms forms by using ElementHost controls, but it will introduce additional complexity which may or may not be warranted).
Related
1.Need to create Dynamically controls like Labels, Buttons.
2.After created dynamically control(label,button),that I can able to select that control and moving to other location on that form.
This is a large question and it's impossible to give you a short answer.
There is a quite good sample for a starting point available at codeproject and csharpcorner. Version #2 of this sample is also available.
There is also WPF designer available at github.
Out of curiousity, is it possible to have 2 application layouts without having to have 2 projects?
Like one layout for desktop/laptops. And then one layout for tablets?
I know winforms only has 1 designer file, and that probably answers my question, but I was curious if i really just needed to re-create a whole new program for a tablet layout, even though it would have all the same functionality as the desktop, with all the same controls, just look slightly different.
I'd put the core functionality in a library assembly (DLL), and write two UI applications that reference the same core assembly.
You can write your own custom LayoutEngine which handles the layout. This way you leave all layout oriented task to your engine and can focus on code.
Here's an article on Microsoft on how to do this (with sample source):
http://msdn.microsoft.com/en-us/library/ms973821.aspx
From the article:
All Windows Forms controls provide a Layout event, along with a host
of other notifications, which enables the writing of a complex layout
code. To facilitate writing reusable layout engines, we can provide a
basic framework.
I am trying to reproduce a window from the Microsoft built-in Registry Editor. The window is the one which is opened when you select "Modify Binary Data..." from the context-menu when a value is clicked.
The goal is to make an identical(!) window in my .NET C# application using Windows Forms.
The problem is the textBox displayed in the window which contains the binary data. I have tried using a RichTextBox, but it isn't as simple as it seems to be especially when it comes to editing data and the behaviour of this textBox.
So I have 2 questions:
How to achieve an identical textBox in C# using Windows Forms? Maybe you know some other ways to reproduce this textBox?
I also need the font name used in this textBox, I couldn't find it :)
Thanks!
I can think of two ways you can approach this. The first is a DataGrid, painstakingly styled to have transparent grid lines and exact margins between columns, with filters to enforce hex digits only. All this, set alongside a richtextbox for the ASCII display, with your code synchronizing the selection between them.
Alternately, you can replace the DataGrid with a collection of TextBoxes, again styled for invisible borders, automatically adding new textboxes to the collection when the user adds more data.
All in all, it seems like an awful lot of work, especially in WinForms - WPF might make this a bit easier, especially the styling, but still a lot of work.
Regarding the name of that control - I tried using Spy++ to sniff it out, and it seems it's registered as a Window Class named "HEX", but I'm not sure that will really get you somewhere:
Here is an open source project containing a hex editor control for Winforms, looking at least very similar:
http://sourceforge.net/projects/hexbox/
I guess you can modify it accordingly to your requirements. But beware, the source code for the control is ~6000 lines of code (including more than a dozen utility classes). It inherits directly from "Control" and does all the text display using GDI+ (so no modified DataGrid or RichTextBox).
Windows Form (in C#) - I need to create a custom listbox control for the following requirement:
There is a listbox with a long list of items. I want the user to be able to click in the list, and then start typing and have it automatically take them to the matching item (I call this "type ahead"). It needs to be able to do this for as many characters as they type that have a match.
This control should be really reusable without much changes.
What are things/points I should keep in mind while developing a reusable custom control? (if you provide a good pattern as a sample... will be more helpful)
In Real World scenario the first decision should be buy vs build. if your application is a serious one and not just for hobby and there is budget for it I would check some of those great controls collections like DevExpress or Telerik for WinForms. You would need a grid as well at some point, eventually, and surely your custom or framework one cannot compete theirs.
I refer to those libraries because i believe they already have a listbox with autocomplete as you described in your requirements. check the online demos on their websites...
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.)