kirsan31 / winforms-datavisualization

System.Windows.Forms.DataVisualization provides charting for WinForms applications.
MIT License
47 stars 19 forks source link

Question: Enhancement #25

Closed paul1956 closed 1 year ago

paul1956 commented 1 year ago

Right now, Legend, Title and other Chart Items in Designer are Local in designer.vb but for my application I want them Friend With Events is there a way to fix this without editing Designer.vb?

The resource designer has an option to control visibility in designer need something like that for custom controls. or just this one.

kirsan31 commented 1 year ago

@paul1956 I am sorry unfortunately I don't know anything about VB :( I don't even understand what you are asking 🤷‍♂️

paul1956 commented 1 year ago

When you create a chart legend, title, etc are private I need them declared with wider scope.

kirsan31 commented 1 year ago

When you create a chart legend, title, etc are private I need them declared with wider scope.

Unfortunately it didn't get clearer 🙄

paul1956 commented 1 year ago

This is the Control and for Chart you can set Modifiers. image I don't see how to do that with the items in Chart like ChartArea, Legend, Series, Titles There are no Design Properties. image

Name for example is in "Data" section not Design Properties.

kirsan31 commented 1 year ago

I think I understand what you mean. You are talking about chart elements that are locals in InitializeComponent?

https://github.com/kirsan31/winforms-datavisualization/blob/18df5ac3cc07db2acad357d40cfc6ae1202cf441/DesignerTest/Form1.Designer.cs#L29-L40

They are locals - not private, so you can't to do anything here. I agree with you that this approach is not always convenient. But it was designed that way, and it was done for a reason. These are the internal elements of the chart and control monitors their life cycle. If you want to use them outside somehow, you'll have to get them from the chart one way or another. And if you are going to store them in global variables (class members), then you need to remember two things:

paul1956 commented 1 year ago

Yes, you now understand, if you look at TabPages which is similar the IDE allows you to declare them with other visibility below is Friend. If there are no events raised I agree it is not a good idea to expose.

Me.Users = New System.Windows.Forms.TabPage()
Friend WithEvents Users As TabPage

I am guessing this is only really important if the Object raises events.

kirsan31 commented 1 year ago

@paul1956

TabPage is not a good example here, because TabPage is a Control itself. DataGridView with DataGridViewColumn is more suitable, but DataGridViewColumn is component too (derived from IComponent)...

GenerateMember and Modifiers are not real properties. They are automatically added by designer in design time only, when you inherit your class from IComponent Interface. And TabControl and DataGridView was designed with that TabPage and DataGridViewColumn are components in mind. But Chart control was designed with opposite approach.

I did a quick test to demonstrate the problems.

The main problem is after we generate member, we will be able to select it and edit properties directly - ignoring all Chart collection editors logic. For example, we will loose all elements dependences by names - editing controls directly can lead to unpredictable errors :( Other problems (I think they solvable): Name property conflict and GenerateMember must be false by default. Snipaste_2023-01-14_11-56-21

P.s. While playing with this I found bug in WinForms designer.

paul1956 commented 1 year ago

As long as the thing does not raise events, the way you are doing it is fine. I just need to access it by name and VB has an easy way to do that similar to C# using. It's where there are events that VB is different then C# and Visual Studio automatically can create the strongly typed handlers.

paul1956 commented 1 year ago

I don't understand why Name is under Misc when for other controls it is under Design except for that since the only thing that raises event as far as I can tell is Chart there is no real issue and this can be closed.

kirsan31 commented 1 year ago

I don't understand why Name is under Misc when for other controls it is under Design

If you look at the screenshot above, then it is present both there and there. And I think it's due to that name of the varibale is differ from name property:

image

except for that since the only thing that raises event as far as I can tell is Chart there is no real issue and this can be closed.

Closing it then...

paul1956 commented 1 year ago

@kirsan31 In case you were wondering what I was up to. This is a medical app for people to monitor an insulin pump with analyze of its data on other tabs. Thanks for making it possible. image

kirsan31 commented 1 year ago

Glad to hear that someone needs it, especially for such a useful cause!