Page 1 of 2

[VB Express Edition] User control troubles

Posted: Mon 11 Jun, 2007 1:07 pm
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)

Posted: Mon 11 Jun, 2007 1:32 pm
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:

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

Posted: Mon 11 Jun, 2007 1:35 pm
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.

Posted: Mon 11 Jun, 2007 3:01 pm
by kv83
Hehe... VBC++ :lol: It just sounds so... funny (no offence)

Posted: Tue 12 Jun, 2007 8:47 am
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)

Posted: Tue 12 Jun, 2007 9:29 am
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.

Posted: Tue 12 Jun, 2007 12:16 pm
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()?

Posted: Tue 12 Jun, 2007 8:28 pm
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)

Posted: Tue 12 Jun, 2007 9:54 pm
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.

Posted: Wed 13 Jun, 2007 1:14 am
by calc84maniac
You called? :D

Posted: Wed 13 Jun, 2007 1:24 am
by Halifax
There is also Microsoft Visual C++ or, VC++ to confuse matters.

Posted: Wed 13 Jun, 2007 11:28 am
by kv83
If you're using VB Express atm, i advice you to step over to C# asap :)

Posted: Thu 14 Jun, 2007 1:57 pm
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.

Posted: Thu 14 Jun, 2007 2:21 pm
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).

Posted: Thu 14 Jun, 2007 2:39 pm
by King Harold
What can C# not do?