Trying to use RGB() function from Core to set Color on .Net control...

This forum is meant for questions and discussions about the X# language and tools
Anonymous

Trying to use RGB() function from Core to set Color on .Net control...

Post 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
2019-05-05 05_33_16-ConvertedApp1 - Microsoft Visual Studio.png (23.98 KiB) Viewed 634 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
2019-05-05 05_34_40-Functions.RGB Method.png (13.49 KiB) Viewed 634 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
2019-05-05 05_40_41-ConvertedApp1 - Microsoft Visual Studio.png (10.95 KiB) Viewed 634 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
2019-05-05 05_47_29-Visual-FoxPro-Toolkit-for-.NET_Common.cs at master · mattslay_Visual-FoxPro-Tool.png (13.34 KiB) Viewed 634 times
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Trying to use RGB() function from Core to set Color on .Net control...

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
FoxProMatt

Trying to use RGB() function from Core to set Color on .Net control...

Post 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);
}
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Trying to use RGB() function from Core to set Color on .Net control...

Post 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().
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Trying to use RGB() function from Core to set Color on .Net control...

Post 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
FoxProMatt

Trying to use RGB() function from Core to set Color on .Net control...

Post 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.
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Trying to use RGB() function from Core to set Color on .Net control...

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Trying to use RGB() function from Core to set Color on .Net control...

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FoxProMatt

Trying to use RGB() function from Core to set Color on .Net control...

Post 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.
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Trying to use RGB() function from Core to set Color on .Net control...

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply