Page 1 of 3
Trying to use RGB() function from Core to set Color on .Net control...
Posted: Sun May 05, 2019 10:49 am
by Anonymous
I am trying to use the RGB() function from XSharp.Core, to set the background color of a .Net UI control.
It gives an error:
Code: Select all
XS0029 Cannot implicitly convert type 'dword' to 'System.Drawing.Color'
- 2019-05-05 05_33_16-ConvertedApp1 - Microsoft Visual Studio.png (23.98 KiB) Viewed 665 times
I also tried to cast the result to Sytem.Drawing.Color, but it still gave an error:
Error XS0030 Cannot convert type 'dword' to 'System.Drawing.Color'
- 2019-05-05 05_34_40-Functions.RGB Method.png (13.49 KiB) Viewed 665 times
On a whim, I added a reference to the
VfpToolkit for .Net, and used
Common.RGB() function and it compiles and runs with no errors.
(
https://github.com/mattslay/Visual-FoxP ... t-for-.NET)
- 2019-05-05 05_40_41-ConvertedApp1 - Microsoft Visual Studio.png (10.95 KiB) Viewed 665 times
Here is the source from from for the
RGB() function in
VfpToolkit for .Net.
- 2019-05-05 05_47_29-Visual-FoxPro-Toolkit-for-.NET_Common.cs at master · mattslay_Visual-FoxPro-Tool.png (13.34 KiB) Viewed 665 times
Trying to use RGB() function from Core to set Color on .Net control...
Posted: Sun May 05, 2019 11:38 am
by robert
Matt,
RGB is a VO compatibilty function. We should probably move it out of XSharp.Core and into XSharp.VO.
VO did not know System.Drawing.Color
Robert
Trying to use RGB() function from Core to set Color on .Net control...
Posted: Sun May 05, 2019 12:06 pm
by FoxProMatt
You can easily use the code from VFP Toolkit for .Net to add this Function correctly typed to XSharp.Core, right?
Here's the C# code:
Code: Select all
/// <summary>
/// This method receives three parameters and returns a color object from those values.
/// In VFP, this method returned a value whereas, in this case we are actually returning
/// a System.Drawing.Color object.
/// <p/><pre>
/// Example:
/// Color o = VFPToolkit.common.RGB(255,255,255);
/// </pre>
/// </summary>
/// <param name="R"></param>
/// <param name="G"></param>
/// <param name="B"></param>
/// <returns></returns>
public static System.Drawing.Color RGB(int R, int G, int B)
{
return System.Drawing.Color.FromArgb(R,G,B);
}
Trying to use RGB() function from Core to set Color on .Net control...
Posted: Sun May 05, 2019 12:22 pm
by Chris
Hi Matt,
Why creating a new function, when you can already use directly Color.FromArgb(r,g,b) ?
The only reason RGB() was implemented in X# is because it is a function available in VO, used in conjunction with the system classes of VO, some of which indeed expect colors in the form of dword values. In Windows.Forms/.Net GDI classes, there's a special class used for representing Colors, that's the Color class, so you'd normally simply use the static method of this class, to obtain your desired color with Color.FromArgb().
Trying to use RGB() function from Core to set Color on .Net control...
Posted: Sun May 05, 2019 1:10 pm
by Karl-Heinz
Hi Chris,
The X# RGB() returns a DWORD, but the VO 2.8 SP3 RGB() returns an INT. Just searched the VO-NG and it seems that the SP4 RGB() introduced the DWORD.
regards
Karl-Heinz
Trying to use RGB() function from Core to set Color on .Net control...
Posted: Sun May 05, 2019 1:32 pm
by FoxProMatt
Why creating a new function, when you can already use directly Color.FromArgb(r,g,b) ?
FoxPro compatibility, so we don’t have to change VFP code.
Trying to use RGB() function from Core to set Color on .Net control...
Posted: Sun May 05, 2019 1:33 pm
by Chris
Hi Karl-Heinz,
Are you absolutely sure? I do not have SP3 to check, but I checked it in VO27 and already in it it returned a DWORD.
Trying to use RGB() function from Core to set Color on .Net control...
Posted: Sun May 05, 2019 1:38 pm
by Chris
FoxProMatt_MattSlay wrote:Why creating a new function, when you can already use directly Color.FromArgb(r,g,b) ?
FoxPro compatibility, so we don’t have to change VFP code.
Ah, OK, so there's a function named RGB() also in VFP? What value does it return? Obviously not a System.Drawing.Color...
In case it does not return a numeric value (which I suspect it does), then we will need to do what Robert said, move the current RGB() function to the XSharp.VO library, and implement a new one in XSharp.VFP, which will behave exactly as it behaves in VFP. People who port VO apps will be using the XSharp.VO library and people porting VFP apps will be using the XSharp.VFP library.
Trying to use RGB() function from Core to set Color on .Net control...
Posted: Sun May 05, 2019 1:45 pm
by FoxProMatt
VFP RGB() returns integer.
See my code sample to Robert above where the VFP Toolkit for .Net has a RGB() function to return Color type.
Most all VFP Functions have been implemented in .Net flavor in that Toolkit.
Trying to use RGB() function from Core to set Color on .Net control...
Posted: Sun May 05, 2019 1:51 pm
by Chris
FoxProMatt_MattSlay wrote:VFP RGB() returns integer.
See my code sample to Robert above where the VFP Toolkit for .Net has a RGB() function to return Color type.
Most all VFP Functions have been implemented in .Net flavor in that Toolkit.
OK, so people who will be using the Toolkit, will be using this version of RGB(). But in order to be fully compatible with VFP in the official X# runtime/VFP dialect, we will probably need to implement RGB() in a way that it returns the same thing as it does in VFP. Possibly the already implemented function will do.