473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

convert type 'object' to 'System.Drawing.Color'

In the following code ,I am getting the errors

Expand|Select|Wrap|Line Numbers
  1. public abstract class Theme
  2. {
  3.     private string sFrmBackGroundImage;
  4.     private Color sFrmTransperncyColor;
  5.  
  6.  
  7.     public object BackGroundImage
  8.     {
  9.         get { return sFrmBackGroundImage; }
  10.         set { sFrmBackGroundImage = value; }Error1:cannot implicitely convert type 'object' to 'string' 
  11.  
  12.  
  13.     }
  14.  
  15.     public object TransperncyColor
  16.     {
  17.         get { return sFrmTransperncyColor; }
  18.         set { sFrmTransperncyColor = value; }Error2:cannot implicitely convert type 'object'   to 'System.Drawing.Color'
  19.     }
  20.  
  21.     public abstract bool SetTheme(ref  Page  frmObj);
  22.  
  23. }
  24.  
I think I can add 'ToString()' in Error1.But what about in case of Error2 How to debug it ?
Jul 26 '07 #1
2 3089
Plater
7,872 Expert 4TB
Why are your get/set functions using Object when you are assigning them to definitive classes?
Why not do this:
Expand|Select|Wrap|Line Numbers
  1. public string BackGroundImage
  2.     {
  3.         get { return sFrmBackGroundImage; }
  4.         set { sFrmBackGroundImage = value; }
  5.     }
  6.  
  7. public Color TransperncyColor
  8.     {
  9.         get { return sFrmTransperncyColor; }
  10.         set { sFrmTransperncyColor = value; }
  11.     }
  12.  
Or if you really need to use the Object you can type cast it
Expand|Select|Wrap|Line Numbers
  1. public Object BackGroundImage
  2.     {
  3.         get { return sFrmBackGroundImage; }
  4.         set { sFrmBackGroundImage = (string)value; }
  5.     }
  6.  
  7. public Object TransperncyColor
  8.     {
  9.         get { return sFrmTransperncyColor; }
  10.         set { sFrmTransperncyColor = (Color)value; }
  11.     }
  12.  
Jul 26 '07 #2
Actually I need to use the Object.Now it is working fine.Thank you very much... :)
Jul 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Toby Mathews | last post by:
Hi, In an ASP.Net application I want to convert open create a FileStream object from a System.Drawing.Image - is this possible? I create an instance of an Image object using the FromFile method,...
11
by: Altramagnus | last post by:
I have a complicated Region object, which I need to draw the outline, but not fill How can I convert the Region object to GraphicsPath object? or How can I draw the outline of the Region object?
1
by: Fritz Switzer | last post by:
With two controls a PictureBox and another "PictureBox like" , Pic2, a control from a dll, I'm stuck on cannot implicity convert System.Drawing.Image to System.Drawing.Bitmap error. How do I...
3
by: Mike in Paradise | last post by:
I have an application that is being passed objects which could either be an instance or a Type in the case of a Static Class When you do the GetType on the object that was originally a Static...
2
by: Billy Greening | last post by:
I have an application in C# that was written as a bunch of individual CS files. I would like to combine these all into single solution that can be editied with the Visual Studio 2003 editor. Does...
4
by: John | last post by:
I want to convert the value of color.RGB of font object to hexadecimal value. How is it possible. Can some one help me. I want to do it through my code internally without using any third party...
4
by: Harry Hudini | last post by:
Hi, I need to run exactly this code in an asp.net file when someone uploads an image, but i dont know C# and im having real issues converting it. If anyone can, could you convert it to VB.net...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
2
by: Ronchese | last post by:
Hi all. Is possible I coerce a value to a determined type informed by a string? See the sample: dim obj as Object obj = SomeConversionType(2, "System.Windows.Forms.DockStyle")
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.