Results 1 to 10 of 10

Thread: [RESOLVED] Finding the constructor for TextBox and other generic controls.

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    51

    Resolved [RESOLVED] Finding the constructor for TextBox and other generic controls.

    I am investigating how far I can go with transparency. I would like to see graphical lines not being covered up by controls. For example, if I make a TextBox transparent, sure it will look odd by being the same color of the background but the graphical line will not be drawn over. Then, optionally, I can fill in a white background for the TextBox and then draw the line on top. A hack, but doable.

    I have found this link that explains how to give controls a transparent background:
    https://msdn.microsoft.com/en-us/lib...VS.100%29.aspx

    However, I don't know how to find the constructor for generic controls and I am not sure if I have to modify or not the setstyle method they give for say a TextBox.

    Cheers, Brent
    Last edited by Mars729; Sep 6th, 2015 at 09:47 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Finding the constructor for TextBox and other generic controls.

    You can't change the constructor for an existing class. In fact, you can't change an existing class at all. What you can do is define your own class, inherit that existing class, then add your own constructors and/or override existing functionality.

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    51

    Re: Finding the constructor for TextBox and other generic controls.

    Just before I turned off my computer last night I found an example to emulate and modify.

    Public Class TransparentTextBox '
    ..Inherits TextBox

    ..Public Sub New()
    ....Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
    ....Me.BackColor = Color.Transparent
    ..End Sub
    End Class

    It doesn't work though, the control (I also tried Label) still paints over the line. I will investigate further...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Finding the constructor for TextBox and other generic controls.

    For future reference, you don't need the dots when posting code. There's a button on the tool bar for formatting code.

  5. #5
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Finding the constructor for TextBox and other generic controls.

    You're going to be very, very disappointed going this route. I've been designing and customizing WinForms controls for nearly 10 years, and transparency is one of the features that usually means writing your own control.

    WinForms controls were designed to be customized to an extent, but to truly make a control transparent you need to be able to control:
    • Its constructor.
    • Its Paint event.
    • Its PaintBackground event.


    You can handle those events in most derived controls, but if you do so you're responsible for drawing everything. So if you want a transparent TextBox, you have to commit to drawing the background, the border, the cursor, the selection highlight, and the string. For some controls, like ListView, it's more trouble than it's worth. I've had great luck with Labels, and decent luck with PictureBoxes, but for most of the rest of them the complexity of the drawing code overwhelms the utility of transparency.

    Here's a better idea before I bog myself down much further.

    Why do you want transparent controls? I can think of a few reasons, and in most of those cases I have some suggestions:

    • Is this just a quick, one-off project? If so, is it more valuable to finish it than to have this trick? If not, why is transparency important to the operation of this program?
    • Is this a game? WinForms is a terrible UI framework for games. You'd do much better investing your time into a framework like Unity. By analogy, it's like switching from a small screwdriver to a hammer when you need to drive nails. Don't listen to people that tell you it's hard, they're just scared you'll finish a project and make them feel guilty for playing video games while you get things done.
    • Is this a larger-scale application? You should really list out what you need to make transparent and why it's important. If it's just for aesthetics, you can probably drop it now and implement it later in the interests of spending your effort finishing rather than polishing. If it's key to the operation of the program, you might want to consider buying third-party controls that already work for the same reason: spending 40 hours to "save" $100 is a waste of 30+ hours (that is, if you have the $100.) If you can't buy controls, I'd strongly suggest considering WPF, where alpha-blended transparency is a native concept rather than a hacked-in afterthought.


    Please explain the true problem, not just the roadblock. You're going to need a LOT of help if we need WinForms transparency, and it helps us give you exactly what you need.
    Last edited by Sitten Spynne; Sep 7th, 2015 at 08:57 AM.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    51

    Re: Finding the constructor for TextBox and other generic controls.

    I am working on a large application and I am doing it my own spare time (hour/day), mostly in the winter. Call me crazy for doing this, but even if I fail it will be a better use of my time than watching TV.

    In brief I want:
    - a ZigZag(tim) data structure as its heart with a simple view of it
    - a photo organizer with about a dozen or so features or so not found in any or just a few photo organizers

    If I get that far I will continue with these features:
    - a simple database for entering wildlife sightings
    - a menuing system to leverage existing tools (including command-line utilities) to enable users to customize their own media player and beyond
    - a text editor that supports transclusions (like in the OpenXanadu demo) and the ability to move words/sentences/paragraphs. Also the ability to pull out the sentences etc out of the document, put them in free space like a freenode (as in FreePlane software) and rearrange them back into the document.
    - a mind-mapping like views

    I originally started this in VB6 and realized it was a mistake developing in that language. I am in Visual Basic Express 2010 currently and I am getting familiar with it. I am nearly finished redoing the Zigzag(tm) core with a custom file format. I took a break to enjoy the spring and summer, lots of birds, dragonflies etc to find but I'm back at it now.

    I had a feeling that I would have to rebuild controls from scratch. Having them appear under controls is not optimal but can be an acceptable option.

    If I were to go the WPF route, and port the limited code in VB Express 2010 Winforms, would I be able to forgo databinding and use my custom file format instead? If I use my custom file format in WPF I will move my code to WPF.

    I will need to go hold of Ted Nelson to see what terms I need to adhere to use his ZigZag(tm) patent. And to find out if any progress has been made on OpenXanadu.

    Personally I believe in his vision of the Xanadu software and should he die before completing his work, I want to be able to at least implement some of this ideas. I am not exactly the most skilled programmer but I am giving it my best shot. (Though I want my vision of the photo organizer first)

  7. #7
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Finding the constructor for TextBox and other generic controls.

    [quote]would I be able to forgo databinding and use my custom file format instead?[quote]
    Data binding is how XAML talks to its code. That's all. Think of it like a new kind of event handler for WPF, only more useful if you're using a Presentation Model pattern like MVVM (which you should be using a PM pattern, even in WinForms.) So yes, you can use your custom file format, because data binding has nothing to do with your actual data (which would be called a "model" in most PM patterns.) If you're curious what that means, I can try to spend less than a page on it, but it's kind of a side topic. (The gist of it is that you should keep your UI separate from your logic. If you follow the patterns right the bulk of your code doesn't care if it's using WinForms, WPF, or Cocoa.)

    I'm looking at some screenshots of the concepts you're talking about and I'm not sure why you think you need a fully transparent textbox? I see rectangles in which you can type text, but those rectangles all have some color. It'd be trivial to make a borderless textbox with the same background color and have it inset inside the rectangle that "owns" it. Maybe you're wanting to use fancy gradients or images? WinForms transparency works best with solid colors, that's for sure. But really editing in that style is an aesthetic convenience, pop-up windows and other techniques could work just fine.

    So why don't you describe what you're really trying to do? Maybe transparent textboxes aren't the best (or easiest) approach. Something led you to ask for a transparent textbox, and I'm curious what the actual UI need is.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    51

    Re: Finding the constructor for TextBox and other generic controls.

    I want the transparency for displaying transclusions. Transclusions are visual links to identical items in different contexts that usually cross the borders of windows.

    Here are two examples. I have taken screen shots from my abandoned VB6 software and added lines in with Paint.

    Scenario 1: From Textboxes (or Labels) to/from Picture Boxes
    This shows a transclusion to the filename of the picture
    Name:  2015-09-07 20_31_31-Capture.jpg
Views: 227
Size:  17.9 KB

    Scenario 2: From Textboxes (or Labels) to/from Datagrids
    This shows a link from the datagrid to the RowColumn view for the item "Buckwheat'
    Name:  2015-09-07 20_52_17-Capture.jpg
Views: 219
Size:  13.3 KB

    Another example from the web:
    Scenario 3: From Richtextbox to Richtextbox
    This is an example from the OpenXanadu demo, not my work, that shows transclusions in a fancy way and for a span of text.
    Name:  2015-09-07 20_57_48-Capture.jpg
Views: 234
Size:  35.3 KB

  9. #9
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Finding the constructor for TextBox and other generic controls.

    I don't see anything in that that requires an extensive suite of transparent controls. Here's the needs I see in both your screenshots and the demo screenshots:

    1. You must be able to draw persistent lines of many colors that can overlap graphical elements. These lines may be transparent as an aesthetic concern.
    2. You must be able to draw arbitrary semitransparent rectangles of any color over elements of the UI. Without transparency, borders could be used, but the "highlight" effect is far too functional to be aesthetic.


    For (1) without transparency, all you need is to be clever with your Form's Paint event handler. To have true transparency, I think you'd best derive a new Control to contain the lines, because you need to alpha blend with controls it will overlap.

    For (2) you need transparency, and I just realized you didn't link to what I thought you did.

    My go-to tutorial for transparency in WinForms seems to have evaporated. It was on a site "bobpowell.net" but it looks like that's not maintained any longer. So I had to dig deeper and find places where I'd made examples. This one implements a control with a transparent bacground that displays an elipse, which is sort of close to displaying a line. In my experience, you usually have to inherit directly from Control and implement what you want from scratch if you want anything approaching overlapping transparent controls. I don't remember if this worked for brushes using a color with alpha channels, which is how you'd do a semitransparent overlay, but you can poke at it and find out.

    (Of course, in WPF there's no question this would "just work".)
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  10. #10

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    51

    Re: [RESOLVED] Finding the constructor for TextBox and other generic controls.

    Thanks for your help. That's all I need for now.

    As far as the OpenXanadu demo goes, I am not sure what used to program it, only that it works in a web browser. In VB, of course, a richtextbox would be a natural choice for something like that. I hope that work is still ongoing on that project, it would be nice to see his designs succeed. If you are curious, the link to where the OpenXanadu demo is at http://www.xanadu.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width