I've searched the web and I can't seem to find anything that will work for me. I've seen plenty of discussion, and even some fairly extensible open-source tools, for code editors that provide line numbers and syntax highlighting.
Here's my dilemma...
I'm working on a "digital code review" project in C#.NET that allows users to specify source files, add them to a particular session, and other users can make comments and line references to the files being reviewed.
Basic requirements:
Must be written in C#.NET
I don't need to be able to edit the text in the text box
Users need to be able to select a line (or multiple lines), to make line references.
It seems to me that I need some fancy implementation of a ListBox control (not a drop-down list) that has some OwnerDraw capabilities to add line numbers and syntax highlighting. Unfortunately, I haven't had any luck putting it together myself, and I can't seem to find a control that's already been written or a reference on how I might be able to accomplish this.
Any suggestions??
I suggest to try ScintillaNet. It has syntax highlight and line numbers (and so much more). However you cannot select more lines only one selection at the time.
I would use a text box control for this, just make it read only and put the line numbers in when you load it. Just a quick question, when you say:
Users need to be able to select a line (or multiple lines), to make line references.
Is this in a web app? How do the users indicate that they want to create a reference (some button somewhere?). Easier to do on windows with a context menu. Where does the user reference to the code go, how does it appear to other users viewing the code?
Related
I'm working on a number-crunching app with some fairly (from my POV) complex math. My first thought was,
Gee, it'd be really nice to be able to take a screen shot in
Mathematica and include it as a comment in my C# source.
I see a cdata value when entering /// alongside summary, remarks, and other options. Custom tags appear to also be supported (as there doesn't appear to be any validation happening).
In order of preference, I'd like to:
Link Mathematica code to my C# source, and have said code appear, in all its Greek-laden glory, as a comment above the method that calls it (or from which it was generated). Bonus points for actually embedding the Mathematica editor in VS!
Link to an image file containing a screenshot of the above, manually generated via Paint and the snip tool, and have VS display it.
Embed the image in a CDATA section, and have it automagically render inside of VS when viewing the code, inline with said code. Generating a base-85 (or whatever) encoded version of an image is trivial. The problem at this point is getting it to display.
Ways that this is possible:
Write an app that overlays an image on the screen and, via magic, keeps it aligned with the source view in VS. (This is ridiculous, but, hey, so is a language that requires you to denote variable names with a $, and yet has a full BNF grammar available to anyone who can Google. Oh, what a world...)
I got nothing.
Suggestions? Is it possible to extend VS so that an image, or control (where Mathematica could be hosted), can appear in the source view?
(note: one of my favorite statements is "It's software. Anything is possible. Give me a 9-volt battery, a paper clip, pocket knife and a monkey hopped up on speed, and we'll make it happen." In this case, I mean within the realm of practicality.)
It looks like this Visual Studio plug-in should solve most of your requirements:
http://visualstudiogallery.msdn.microsoft.com/793d16d0-235a-439a-91df-4ce7c721df12
Presently I'm trying to build up a text editor for the PHP language which should have the feature of code completion, i.e. if i start to type a word a dynamically created drop down list will display all available keywords starts with my typed letters. Can any body suggest me how it can be done. Idea will be enough for me. If possible please provide me a link to such simple application build in C#.
Considering that in general it's not an easy task, so there is no some "easy" application.
Even if in general idea is not a rocket science. You need to define a dictionary of words, corresponding to some key. When you type "." (in C#) you have to pick from the dictionary all words corresponding to the key equal to the word found on left side from the "."
To do it real working applicaiton is not so easy. By the way I can recommend to have a look on MonoDevlop look on their editor.
I worked with it years ago to make a simple editor for DSL company needed, and spend not small amount of time to correctly understand intenals, integrate well "my new language", "detach" control from Mono and inject into our applicaitons, like a dockable window.
If I where you I would really try to avoid the wheel... code completion is something that most IDE's now come with so what you are after is already available...
That being said, what I would try would be to go over the PHP API and construct a Suffix tree. This type of tree usually allow for a fast way to look for a given word. Once you index the API, you would also add in any other variable the user adds while he/she is performing the actual programming.
You could kick the search automatically in your suffix tree after the user has entered the 3rd letter, or maybe provide means for the user to activate it manually, like the Ctrl-Space keyboard most IDE's (Visual Studio, Netbeans, Eclipse, etc) have.
Note that this could get tricky, since you might want to select the appropriate variable type.
I have a textbox and a button in one page.I want to enter a word in the textbox and click the button. After clicking the button I want to display the name of the web pages containing the word entered in the textbox. So please tell me how to do it? I am using C#.
So you want to create a search engine internal to your website. There are a couple of different options
You can use something like google custom search which requires no coding and uses the google technology which I think we all agree does a pretty good job compared to other search engines. More information at http://www.google.com/cse/
Or you can implement it in .net which I will try to give some pointers about below.
A search engine in general exists out of (some of) the following parts:
a index which is searched against
a query system which allows searches to be specified and results shown
a way to get documents into the index like a crawler or some event thats handled when the documents are created/published/updated.
These are non trivial things to create especially if you want a rich feature set like stemming (returning documents containing plural forms of search terms), highlighting results, indexing different document formats like pdf, rtf, html etc... so you want to use something already made for this purpose. This would only leave the task of connecting and orchestrating the different parts, writing the flow control logic.
You could use Lucene.net a opensource project with a lot of features. http://usoniandream.blogspot.com/2007/10/tutorial-implementing-lucenenet-search.html explains how to get started with it.
The other option is Microsoft indexing service which comes with windows but I would advice against it since it's difficult to tweak to work like you want and the results are sub-optimal in my opinion.
You are going to need some sort of backing store, and full text indexing. To the best of my knowledge, C# alone is not enough.
How do I syntax highlight in a richtextbox control AS THE USER TYPES and USING A String[] keywords. I will be publishing a lightweight notepad to the web soon and I want it to have syntax highlighting. I am using Windows forms. Can someone post a code example?
RichTextBox syntax highlighting (talks about RichTextBox itself - minimal features but exactly what you asked for here)
A textbox/richtextbox that has syntax highlighting? [C#] (talks mostly about other ways of doing it)
The Scintilla control is an excellent source code editor that includes syntax highlighting amongst a whole range of other features. You can embed it in your own app and there is a .NET wrapper available.
With Scintilla you can specify the keywords and it will then apply the syntax highlighting as you type.
Are you using WinForms or WPF?
If WPF, you could have a look at AvalonEdit. It's free and open source, and it's used in SharpDevelop (open source IDE).
You can change the font of selected words in the richtextbox. Take a look at the Select and SelectedFont properties of the control.
But essentially, you need to iterate through the words, check if a word is present in your keywords, and then change the font, using the above-mentioned properties.
Not exactly an answer to your question, but have you looked at the text editor component from SharpDevelop? It's quite lightweight (<200kB IIRC), can be easily embedded in WinForms applications and has syntax highlighting for several languages built in.
Otherwise, you might want to look at this CodeProject page. It reformats the RTF while you type, which is not very efficient for large files, and it contains a few creepy catch (Exception) { } blocks, so I'm not sure if I would use it in a life-critical application, but it's definitely a good starting point to see how it can be done.
Syntax highlighting is not an easy task to perform efficiently. Many solutions you can find (like the ones involving modification of RTF) are a one time solution. If you want to highlight and un-highlight words on the fly during edition, your code has to be ready for it. I would not reinvent the wheel and use ICSharp.TextEditor or alike to solve your problem.
One of the guys I work with needs a custom control that would work like a multiline ddl since such a thing does not exist as far as we have been able to discover
does anyone have any ideas or have created such a thing before
we have a couple ideas but they involve to much database usage
We prefer that it be FREE!!!
We use a custom modified version of suckerfish at work. DB performance isn't an issue for us because we cache the control.
The control renders out nested UL/LIs either for all nodes in the web.sitemap or for a certain set of pages pulled from the DB. We then use jQuery to do all the cool javascript stuff. Because it uses such basic HTML, it's pretty easy to have multi-line or wrapped long items once you style it with CSS.
Have a look at EasyListBox. I used on a project and while a bit quirky at first, got the job done.
I'm not sure exactly what you mean by multi-line, but if it is selecting multiple elements in a drop down list, see this demo.
If its showing elements that wrap mulitple lines in a drop down, see this demo. You can put a break in the HTML to achieve what you might be looking for. I've used this control in this manner before, so I can confirm it works.
Good luck.