[VB Express Edition] User control troubles

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

[VB Express Edition] User control troubles

Post by driesguldolf »

I am currently making some sort of textbox usercontrol to support additional stuff like syntax coloring, highlithing, error marking and stuff but as you migh have guessed microsoft's in the way

Some weird stuff that happens:
- When I change the font property in the form designer suddenly the scroll bars are moved! (not sure how this is posible because the scroll bars are only affected when the control is resized)
- I think that the textrenderer.measuretext routine isn't so accurate because sometimes I can't scroll far enought to the right to show all the text (this happens only with specific fonts tough) (not sure how to explain this, I hope it's clear enough)
Last edited by driesguldolf on Tue 12 Jun, 2007 8:30 pm, edited 1 time in total.
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

Some more specific stuff about no2:

For clearity:
private contents() as string
private realheight as integer=me.height-horizscroll.height
private realwidth as integer=me.width-vertscroll.width

Code: Select all

    Public Sub ValidateStuff()
        Dim x As Integer

        VisibleLines = Math.Floor(Realheight / Font.Height)
        VertScroll.Enabled = False
        If VisibleLines < Contents.Length Then
            VertScroll.Maximum = Contents.Length - 2 ''(Why -2? Dunno, it just works)
            If VisibleLines < 1 Then VisibleLines = 1
            VertScroll.Enabled = True
            VertScroll.LargeChange = VertScroll.Maximum / (Contents.Length / VisibleLines) ''(Another guess of mine could be the source of all troubles)
        End If

        x = LargestLine()
        HorizScroll.Enabled = False
        If x > RealWidth Then
            HorizScroll.Maximum = x + VertScroll.Width
            HorizScroll.Enabled = True
            HorizScroll.LargeChange = HorizScroll.Maximum / (x / RealWidth) ''(This is probabely where it goes wrong)
        End If
    End Sub

    Private Function LargestLine(Optional ByRef n As Integer = 0) As Integer
        Dim l As Integer = Contents.Length - 1
        Dim x As Integer
        For n = n To l
            x = TextRenderer.MeasureText(Contents(n), Font).Width
            If x > LargestLine Then LargestLine = x
        Next
    End Function
But actually I've no idea of the things commented
But that's the fun of vbc++ just try it and see if it works and don't ask questions if it does... :mrgreen:
Last edited by driesguldolf on Tue 12 Jun, 2007 8:23 am, edited 1 time in total.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Re: [VB Express Edition C++] User control troubles

Post by benryves »

driesguldolf wrote: - When I change the font property in the form designer suddenly the scroll bars are moved! (not sure how this is posible because the scroll bars are only affected when the control is resized)
Automatic Scaling in Windows Forms - forms and their controls can change size when the font is changed. This might be related to your problem.

- I think that the textrenderer.measuretext routine isn't so accurate because sometimes I can't scroll far enought to the right to show all the text (this happens only with specific fonts tough) (not sure how to explain this, I hope it's clear enough)
I've only used Graphics.MeasureString myself, and it has been entirely accurate in all cases thus far. The only issue I can think of is that it (by default) takes into account a little extra padding for overhanging characters and so returns a slightly too-wide value. Pass StringFormat.GenericTypographic to prevent this.

Edit: What exactly is VBC++? :) The language would be VB8.
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

Hehe... VBC++ :lol: It just sounds so... funny (no offence)
Image
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

benryves wrote:
driesguldolf wrote:- When I change the font property in the form designer suddenly the scroll bars are moved! (not sure how this is posible because the scroll bars are only affected when the control is resized)
Automatic Scaling in Windows Forms - forms and their controls can change size when the font is changed. This might be related to your problem.
Yep that was the problem, autoscalemode = "Font" :) thanks
benryves wrote:
driesguldolf wrote:- I think that the textrenderer.measuretext routine isn't so accurate because sometimes I can't scroll far enought to the right to show all the text (this happens only with specific fonts tough) (not sure how to explain this, I hope it's clear enough)
I've only used Graphics.MeasureString myself, and it has been entirely accurate in all cases thus far. The only issue I can think of is that it (by default) takes into account a little extra padding for overhanging characters and so returns a slightly too-wide value. Pass StringFormat.GenericTypographic to prevent this.
Weird, it is sometimes to wide and sometimes too small (drawed a string and underlined it with the measurestring thingie) but the graphics.measurestring works perfect thanks
One more question: I cannot use it directely (graphics.measurestring(...)) it gives me an error (non shared member requires object reference stuff) I have a workaround tough
benryves wrote:Edit: What exactly is VBC++? Smile The language would be VB8.
Is it called VB8? Didn't knew that, I actually invented VBC++, it means Visual Basic [express edition] C++
kv83 wrote:Hehe... VBC++ Laughing It just sounds so... funny (no offence)
I don't think I get the joke but couldn't think of a better name :D

hmmm....
Maybe I shouldn't quote so much text (after all I just post the same text) it just wastes valuable space... But it looks professional and hides the fact that I'm a complete newb at VBEDC++ 8)
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

There is no such thing as VBC++ afaik. It's either Visual Basic or C++. And seeing your code, it's Visual Basic.
Image
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

To emphasise kv's point - C++ is a language. VB is another, completely different, language.

VB6 was the last "classic" VB. VB7, which targeted .NET 1.0/.NET 1.1, is a different language underneath, but retains VB6 syntax for compatibility. It has a much cleaner object-orientated layout than VB6 attempted, and changes the way errors were handled.

VB8 is much the same as VB7, but adds support for .NET 2.0 constructs (eg generics).

To confuse issues, Microsoft released .NET 3.0 with a number of new classes in the framework's class library, but no new language features - so VB9 will target .NET 3.5, and adds a number of new language features (check my Orcas post in Off Topic). ;)
driesguldolf wrote:One more question: I cannot use it directely (graphics.measurestring(...)) it gives me an error (non shared member requires object reference stuff)
A Graphics object can have a number of transformations applied to it at runtime, so it makes sense to keep things relating to the size and position of elements as an instance member. Use CreateGraphics()?
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

benryves wrote:Use CreateGraphics()?
Ah forgot about him thanks

Hmmm alot more troubles have arisen, so this just has to wait until I'm more experienced

Maybe I'll write an on-calc compiler with a simple userinterface for quick and small programs... Really Z80 is alot easier than VB8 8) plus no one has ever written an on calc compiler (not that I know of)
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

People have indeed written on-calc assemblers. You can find one here:

http://www.ticalc.org/archives/files/fi ... 39241.html

Perhaps you could ask the author of that for some pointers.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
User avatar
calc84maniac
Regular Member
Posts: 112
Joined: Wed 18 Oct, 2006 7:34 pm
Location: The ex-planet Pluto
Contact:

Post by calc84maniac »

You called? :D
~calc84maniac has spoken.

Projects:
F-Zero 83+
Project M (Super Mario for 83+)
User avatar
Halifax
Sir Posts-A-Lot
Posts: 225
Joined: Mon 01 Jan, 2007 10:39 am
Location: Pennsylvania, US

Post by Halifax »

There is also Microsoft Visual C++ or, VC++ to confuse matters.
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

If you're using VB Express atm, i advice you to step over to C# asap :)
Image
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

tr1pea1 wrote:People have indeed written on-calc assemblers. You can find one here:

http://www.ticalc.org/archives/files/fi ... 39241.html

Perhaps you could ask the author of that for some pointers.
They look nice, I was thinking of an APP with it's own IDE. I thought of adding help to every intruction and stuff (lots of memory needed), but it has to wait until Puzzle Action is finished (points at signature)
kv83 wrote:If you're using VB Express atm, i advice you to step over to C# asap Smile
I think I will wait for that, there are so many languages and I have no idea wich one is the best, it also takes a while to really know a language and I don't want to have wasted my time on a crappy language.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

driesguldolf wrote:
kv83 wrote:If you're using VB Express atm, i advice you to step over to C# asap Smile
I think I will wait for that, there are so many languages and I have no idea wich one is the best, it also takes a while to really know a language and I don't want to have wasted my time on a crappy language.
It took me all of half an hour to make the switch and feel comfortable with it. C# has a terser, cleaner syntax than VB. (Admittedly, VB can do some things that C# can't, but C# can do more important things that VB can't).
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

What can C# not do?
Post Reply