Results 1 to 9 of 9

Thread: VB.NET color to WPF color

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Denmark
    Posts
    216

    VB.NET color to WPF color

    Hi,
    How do I set a color in my WPF (System.Windows.Media.Color) from VB.NET
    I get an error : Value of type System.Drawing.Color cannot be converted to System.Windows.Media.Color

    Thank you in advance

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

    Re: VB.NET color to WPF color

    You use a System.Drawing.Color in Windows Forms. If you're using WPF then don't use a System.Drawing.Color in the first place. Use the right type; don;t convert the wrong type to the right type. So, where is this colour data coming from in the first place?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Denmark
    Posts
    216

    Re: VB.NET color to WPF color

    Ok
    I have an application in vb.net from which I like to change some colors in my WPF application located in the same Solution.
    In my WPF project I have an Richtextbox in which I would like to change text color (Sytem.Windows.Media.Brush).
    I also have a DropShadowEffect where I would like to change the color (System.Windows.Media.Color)
    How do I do this from vb.net ?
    TIA

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

    Re: VB.NET color to WPF color

    You are confused. You're talking about VB.NET and WPF as though they are somehow alternatives. They are not. VB.NET is a programming language and WPF is an application technology. You can create a WPF application using VB.NET or C# as the programming language and you can create applications with VB.NET as the programming language that use WPF, Windows Forms, ASP.NET Web Forms, MVC or various other options.

    So, what are you actually asking for? This WPF project of which you speak; is it an application or a library? This VB.NET project of which you speak; is it an application or a library and, if it's an application, what technology does it use? Are these two projects actually part of the same application? If not, what's the relationship?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Denmark
    Posts
    216

    Re: VB.NET color to WPF color

    Hi Again,
    Maybe I made it difficult to understand.
    I have a solution with my vb.net project (main) and my WPF project. From the beginning I started out doing my programming in vb.net. So all my programming is done in vb.net as a programming language. The WPF is only for showing some transparent forms.
    The only reason I included an WPF project was because Windows Forms are not good at true transparency.
    I hope you understand what I mean.
    Now in the WPF shown from my vb.net application by button click. I would like to change the colors as written in my previous post.

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

    Re: VB.NET color to WPF color

    Well, if you need a System.Windows.Media.Color then create a System.Windows.Media.Color rather than a System.Drawing.Color. Just create what you need.

    If you have no choice but to convert then one has a ToArgb method and the other has a FromArgb method.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Denmark
    Posts
    216

    Re: VB.NET color to WPF color

    Thank you. I will give it a try

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: VB.NET color to WPF color

    Why are you mixing Winforms and WPF? They have some very fundamental differences in how the function.

    Can't you just switch entirely to WPF?

    Timer's are different. Delegating to different threads is very different.

    In WPF I do this (it's C#, not VB - but you should get the idea).

    Code:
    SolidColorBrush tbColor = (SolidColorBrush)new SolidColorBrush(System.Windows.Media.Color.FromRgb(208, 215, 223));
    and also this

    Code:
    lgb.GradientStops.Add(new GradientStop((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#FFFFFFFF"), 0.0));

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Denmark
    Posts
    216

    Re: VB.NET color to WPF color

    Hi szlamany,
    Thank you. I will try your solution.
    I can't switch because my program made in vb.net is almost finished and also because of what I have read vb.net is a real programming language.
    I didn't expect it to be that complicated to choose a color from my vb.net and set it in the wpf.

Tags for this Thread

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