8 Replies - 2553 Views - Last Post: 08 August 2012 - 06:09 PM Rate Topic: -----

#1 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 23
  • View blog
  • Posts: 184
  • Joined: 10-March 12

listobox word wrap changes font

Posted 07 August 2012 - 10:59 AM

hello!
i have a multi line textbox which i am using for a Notepad-like text editor. In my program, i included a button for toggling word wrap on and off. The problem is, whenever i change the word wrap property of my text box, the font style used by the text inside it changes! I am using a font that is installed in the font folder of windows, i have no problems with it, so i guess the problem is not because of the font, but because of the program itself. I even tried to specificaly define the font to use, after the word wrap command, like this:

Private Sub FlatButton22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlatButton22.Click
        If FlatButton22.Text = "WORD WRAP" Then
            FlatButton22.Text = "WORD WRAP OFF"
            doc.WordWrap = True
            doc.Font = New Font("lcars", 16, FontStyle.Regular)
        ElseIf FlatButton22.Text = "WORD WRAP OFF" Then
            FlatButton22.Text = "WORD WRAP"
            doc.WordWrap = False
            doc.Font = New Font("lcars", 16, FontStyle.Regular)            
        End If
End Sub



but it still not working, and as soon as i click the wordwrap button, the font of the textbox changes. I dont know why this is happening, but its already driving me out of my minds, because i really need to use that specifical font! thank you in advance for any suggestions!

This post has been edited by rusoaica: 07 August 2012 - 11:05 AM


Is This A Good Question/Topic? 0
  • +

Replies To: listobox word wrap changes font

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,374
  • Joined: 02-June 10

Re: listobox word wrap changes font

Posted 08 August 2012 - 11:30 AM

What is a Listobox ?
If this is a third-party control that you purchased and imported the class to your project that could be a problem. Try using a Microsoft standard Listbox and see if the same problem still persists. If the problem goes away then you know it was the third party control. If it stays, then you know it isn't the control.

You say "the font style changes" but you don't say *how*. Can you provide two screen shots showing us the difference?


Tip: Don't try to use a single button and swap the text like that. Its a pain in the ass for long term maintenance. It also means your button text is in the program coding so language localization becomes harder. Instead make two buttons, place them on top of each other and use the .IsVisible property.

The C# below should works as good psuedo code for you while still making you write your own VB.NET. As you can see we have a property for UseWordWrap. Clicking the button for wrapOn or wrapOff only has to do one thing: Set the property. The property then does the rest of the work. This way you can have a dozen different triggers (menu option, context menu, control key combo etc.) that don't duplicate the functionality. They just set the property.

bool UseWordWrap
{
   get { return _usewordwrap; }
   set { 
          doc.WordWrap = value;
          btn.WrapOn.IsVisible = !value;
          btn.WrapOff.IsVisible = value;
        }
}

btnWrapOn_Click(object sender, eventargs e)
{   
    UseWordWrap = true;
}

btnWrapOff_Click(object sender, eventargs e)
{
    UseWordWrap = false;
}




Some of my common tips (some may apply more than others to your specific style):
  • You have to program as if everything breaks, nothing works, the cyberworld is not perfect, the attached hardware is flakey, the network is slow and unreliable, the harddrive is about to fail, every method will return an error and every user will do their best to break your software. Confirm everything. Range check every value. Make no assumptions or presumptions.

  • Take the extra 3 seconds to rename your controls each time you drag them onto a form. The default names of button1, button2... button54 aren't very helpful. If you rename them right away to something like btnOk, btnCancel, btnSend etc. it helps tremendously when you make the methods for them because they are named after the button by the designer.btnSend_Click(object sender, eventargs e) is a lot easier to maintain than button1_click(object sender, eventargs e)

  • You aren't paying for variable names by the byte. So instead of variables names of a, b, c go ahead and use meaningful names like index, timeOut, row, column and so on. You should avoid 'T' for the timer. Amongst other things 'T' is commonly used throughout C# for Type and this will lead to problems. There are naming guidelines you should follow so your code confirms to industry standards. It makes life much easier on everyone around you, including those of us here to help. If you start using the standards from the beginning you don't have to retrain yourself later.
    You might want to look at some of the naming guidelines. Its a lot easier to start with good habits than to break bad habits later and re-learn.

    [list]
  • Guidelines for names
  • Naming guidelines
  • Design guidelines for classes


[*]Try to avoid having work actually take place in GUI control event handlers. It is better to have the GUI handler call other methods so those methods can be reused and make the code more readable. This is also how you can send parameters rather than use excessive global variables. Get in this habit even if you are using WinForms because WPF works a lot under the idea of "commands" and this will get you working towards that. Think of each gester, control click, menu option etc. as a command to do something such as a command to SAVE. It doesn't matter where the command comes from, all sources should point at the same target to do the actual saving.
Spoiler


[*]Don't replace lines of code that don't work. Instead comment them out and put your new attemps below that. This will keep you from re-trying the same ideas over and over. Also, when you come back to us saying "I've tried this 100 different ways and still can't get it", we can actually see what you tried. So often a failed attempt is very very close and just needs a little nudge in the right direction. So if we can say "See what you did in attempt 3... blah blah" it helps a lot

Spoiler

If you are using Visual Studio you can select a block of lines and hit control+k control+c (Kode Comment) to comment it out. control+k control+u (Kode Uncomment) to uncomment a selected block.
Was This Post Helpful? 1
  • +
  • -

#3 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 23
  • View blog
  • Posts: 184
  • Joined: 10-March 12

Re: listobox word wrap changes font

Posted 08 August 2012 - 02:51 PM

ohh, tlhIn`toq, my mistake!! i just noticed that i typed LISTBOX with the word TEXTBOX in mind.. sorry, my bad! so, its not about a third party component, it is just a regular textbox! when i say the font changes, i mean that, say, if the font i have installed and i want to use is named "lcars", when i use the word wrap function, the text turns to Lucida Console font style... even if i specificaly declare the font to use AFTER the word wrap command, like this:

doc.wordwrap = true
doc.font = new font("lcars", 16, FontStyle.Regular)



i included two screen shots, first is how the text looks when the program starts, second is how the text font style changes after i click word wrap button

Posted Image
Posted Image

by the way, great ideea with the property pice of code!

This post has been edited by rusoaica: 08 August 2012 - 03:00 PM

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,374
  • Joined: 02-June 10

Re: listobox word wrap changes font

Posted 08 August 2012 - 04:48 PM

I would suggest you play with setting the font to a few other things.
I think what is happening is that "lcars" isn't being recognized as the font family name, so it is defaulting.

Maybe the REGISTERED name is "lcars sans" or "lcars demi" etc.

Just for experimentation: add a drop down to pick "Courier", "Gothic", "Lucinda", and make sure you can really select them. Once you know for certain the syntax for font selection you can use KNOWN GOOD technique to narrow down the right naming for your LCARS font.

Nice work with the GUI by the way. After all this work are you doing this with WPF? I'd hate to see you do all this for WinForms when WPF would get you so much more flexibility and forward-compatibility with Win8
Was This Post Helpful? 1
  • +
  • -

#5 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 23
  • View blog
  • Posts: 184
  • Joined: 10-March 12

Re: listobox word wrap changes font

Posted 08 August 2012 - 05:05 PM

you were right!!! when i was adding the font within the visual studio IDE, it was showing it in the font list only as "lcars"... but when i looked inside the windows\fonts directory, it was "LCARS Regular"! I had no clue that was the problem... it almoust brought me to dispair :)
about the GUI, i am a very big fan of the Star Trek TV show and i am using the GUI style that was used on the screens of the computers inside the starships... that GUI style is known as LCARS - an acronym for Library Computer Access/Retrieval System, which looks like this. But to be honest, i just begun programming in January this year, so despite the fact that since then i learned a great deal, im still at the beginning of the path... So, to my shame, i dont even know what WPF is and what brings it plus instead of normal WinForms... but now that you suggested so, i will document myself about it, for sure! I want to learn as much as i can! :)
By the way, this is the second time you help me in delicate situations, the first time was with the custom calendar control, i dont know if you still remember. But the program which included that control is now finished, and you can see a few screenshots of it here. Thank you again!
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,374
  • Joined: 02-June 10

Re: listobox word wrap changes font

Posted 08 August 2012 - 05:40 PM

Regarding your "Captain's Log" application... You might want to see this:

http://itunes.apple....d363299583?mt=8
Was This Post Helpful? 0
  • +
  • -

#7 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 23
  • View blog
  • Posts: 184
  • Joined: 10-March 12

Re: listobox word wrap changes font

Posted 08 August 2012 - 05:47 PM

before i started designing that program, i did a bit of research over the subject and found some interesting results. So when i begun working on it, i started with the ideea in mind to include all the features that i have seen on ather applications like it. Too bad i did not stumble accross this one too, i might have implemented that "share to facebook" or "email to a friend" feature. But, there's never too late for an update!
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,374
  • Joined: 02-June 10

Re: listobox word wrap changes font

Posted 08 August 2012 - 06:06 PM

I *HIGHLY* recommend planning for language localization starting now.
Its a lot easier to add Spanish, Russian, Italian resource files down the line if you haven't hard coded all your strings from day one.
Was This Post Helpful? 0
  • +
  • -

#9 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 23
  • View blog
  • Posts: 184
  • Joined: 10-March 12

Re: listobox word wrap changes font

Posted 08 August 2012 - 06:09 PM

im always open minded to suggestions, friend! Thank you for pointing me out in the right direction!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1