Skip to main content
gamedev.net
🔒 Locked

[.net] another c# problem (RANT)

Started by cignox1 9 replies 2k views
Original Post
cignox1
cignox1
I'm really pissed off! When I first saw C# I thought "they took java and removed the annoying things and added the nice thins: it's a beatiful language". Now I still think that the language is very good, but the library and the documentation are really bad! Let me explain: -First I tried to modify by hand the field Rtf of a RichTextBox. The documentation says I can do this, but it didn't worked. I've spent 3 days to discover that RTB automatically removes those tags that are not used by the text. -Then I tried to get the current font from the RTB. I first read the name and then the size (two properties of the font class). Nothing, the code didn't work properly until I discovered that I had (don't know why) to first get the whole font object in a local reference, and the on that reference ask for the two values. Why? Nowhere they say you need to do this way. -Now I'm creating an OpenFileDialog class. I set a few filters but when the user switches from one filter to another the dialog shows nothing: just as no files with that extension exist. This is the code:

                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Rich Text Format (*.rtf)|*.rtf|Text files (*.txt)|*.txt|All files (*.*)|*.*";
                open.FilterIndex = 1;
                open.DefaultExt = ".rtf";
                if (open.ShowDialog() == DialogResult.OK)
                {
                    CreateDocument(open.FileName);
                }

First it shows the rtf files. Then if I swich to all files or txt nothing appears (as if the window doesn't update the content). Nothing is displayed even if i go back on rtf files. Help me please while I keep looking for a solution! Sorry for the lenght of the post.
Niksan2
Niksan2
I tried that exact code you posted with the createdocument commented out and it works fine here under .net 2.0, shows my rtf's by default after changing the directory to a place that had an rtf, and when I selected the all files, it showed me the rtf and many .bin/.xls/.bmp I had in the same directory.
cignox1
cignox1
Thank you, I was quite sure it wasn't a problem of code because I've found a guy (on a forum) that once had the same problem: he was writing two apps, and using the very same code he was having that problem on one of the app but not on the other one. I will try by reinstalling the .Net enviroment...
TheTroll
TheTroll
Just a little comment here. It is not C# you are having trouble with, it is .net.

theTroll
cignox1
cignox1
Quote:
Original post by TheTroll
Just a little comment here. It is not C# you are having trouble with, it is .net.

theTroll


Yep, in fact I've said that I like the language, but the libray is giving me a lot of trouble lately... anyway I wrote c# in the title just to make it clear which language I was used (in case it matters).

I tried removing and reinstalling everything, but nothing worked for me. I wrote the smallest app I could think of to show the problem:
using System;using System.Windows.Forms;class Mainclass{	public static void Main()	{       OpenFileDialog open = new OpenFileDialog();                open.Filter = "Rich Text Format (*.rtf)|*.rtf|Text files (*.txt)|*.txt|All files (*.*)|*.*";                open.FilterIndex = 1;                open.DefaultExt = ".rtf";                if (open.ShowDialog() == DialogResult.OK)                {					Console.WriteLine("Apri");                }	}}


This code show this strange behaviour on my machine.
Some suggestion?
Thank you!
Machaira
Machaira
Code works just fine on my machine as well. I'd say it's not .NET, it's your machine. I'm assuming you're running .NET 2.0 on XP SP2? If not what's the specs on your machine?
Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development
cignox1
cignox1
Quote:
Original post by Machaira
Code works just fine on my machine as well. I'd say it's not .NET, it's your machine. I'm assuming you're running .NET 2.0 on XP SP2? If not what's the specs on your machine?


XP Professional SP2. I've installed .NET 2.0 and also the dotnetfx3.exe file. Same behaviour both from the Visual Studio and from command line using directly the csc command. Debug and Release seem to behave the same way. I have 1gb of ram, athlon xp 2600Mhz.
I really hope to find a solution...
Many thanks to you all.
guardian24
guardian24
[STAThread] attribute is needed before your Main().
Like:

[STAThread]
public static void Main()
{


The VS2005 debugger shows this immediately...

Btw, DefaultExt does not need the dot.
For example:
open.DefaultExt = "rtf";

And the default for FilterIndex is 1.




Lenin said: "Study! Study! Study!"

capn_midnight
capn_midnight
Quote:
Original post by TheTroll
Just a little comment here. It is not C# you are having trouble with, it is .net.

theTroll


It's not .NET that is the problem, it's lack of reading comprehension.

This isn't the appropriate forum for rants. Try the lounge next time.
TheTroll
TheTroll
Quote:
Original post by capn_midnight
Quote:
Original post by TheTroll
Just a little comment here. It is not C# you are having trouble with, it is .net.

theTroll


It's not .NET that is the problem, it's lack of reading comprehension.

This isn't the appropriate forum for rants. Try the lounge next time.


I was quiet aware of that midnight, I was trying to be polite.
theTroll

Wildfire
Wildfire
I know this is a little off-topic, and maybe you did this in the actual code, but I suggest making use of the "using" keyword.

using(OpenFileDialog open = new OpenFileDialog()){    open.Filter = "Rich Text Format (*.rtf)|*.rtf|Text files (*.txt)|*.txt|All files (*.*)|*.*";    open.FilterIndex = 1;    open.DefaultExt = ".rtf";    if (open.ShowDialog() == DialogResult.OK)    {        // -- code --    }}


This will Dispose the OpenFileDialog on close. Probably not a big issue right now, but still a good thing to get used to early on.

Your code works fine here also.
How do I set my laser printer n stun? o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.