473,805 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change shape of thumb to ellips in wpf

I'm writing a windows app in WPF and want to change the shape of a thumb to
an ellipse. Is this possible? also, the edges of the thumb are beveled.
Is it possible to change this to a flat look and if so, how?

Here's how I'm creating my thumb so far.
Expand|Select|Wrap|Line Numbers
  1. cornerThumb = new Thumb();
  2. // Set some arbitrary visual characteristics.
  3. cornerThumb.Cursor = customizedCursor;
  4. cornerThumb.Height = cornerThumb.Width = 10;
  5. cornerThumb.Opacity = 0.40;
  6. cornerThumb.Background = new SolidColorBrush(Colors.MediumBlue);
Thanks for any input.
--
Jan 9 '07 #1
6 21823
You'll probably get better help in the Avalon newsgroup (or the MSDN
Forums), but yes, it's possible. It's easier to represent in XAML, but what
you want to do is override the visual template with your new visual:

Expand|Select|Wrap|Line Numbers
  1. <Thumb Height="10" Width="10" Opacity=".4" Background="MediumBlue">
  2. <Thumb.Style>
  3. <Style TargetType={x:Type Thumb}>
  4. <Style.Setters>
  5. <Setter Property="Template">
  6. <Setter.Value>
  7. <ControlTemplate TargetType="{x:Type Thumb}">
  8. <Ellipse.../>
  9. </ControlTemplate>
  10. </Setter.Value>
  11. </Setter>
  12. </Style.Setters>
  13. </Style>
  14. </Thumb.Style>
  15. <Thumb.Cursor>
  16. </Thumb.Cursor>
  17. </Thumb>
Jan 9 '07 #2
Thanks Keith. I hope you don't mind that I revised your code a little as
follows:

Expand|Select|Wrap|Line Numbers
  1. <Window x:Class="WindowsApplication1.Window1"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="WindowsApplication1" Height="300" Width="300"[quote]
  5.  
  6. <Thumb Height="10" Width="10" Opacity=".4" Background="MediumBlue">
  7. <Thumb.Style>
  8. <Style TargetType="{x:Type Thumb}">
  9. <Setter Property="Template">
  10. <Setter.Value>
  11. <ControlTemplate TargetType="{x:Type Thumb}">
  12. <Ellipse Width="10" Height="5" Stroke="Blue"
  13. StrokeThickness="2"></Ellipse>
  14. </ControlTemplate>
  15. </Setter.Value>
  16. </Setter>
  17. </Style>
  18. </Thumb.Style>
  19. </Thumb>
  20. </Window>
#Styling and Templating
http://msdn2.microsoft.com/en-us/library/ms745683.aspx
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.
Jan 9 '07 #3
Walter,

This was a good start, but I need to do everything via c# and not xaml. the
link you provided also helped me in that direction, but its still not
working yet. I have a sample with 1 window and 1 button and a resource file
for the thumb's style. Here's the resorce xaml:
Expand|Select|Wrap|Line Numbers
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.         
  5.                 >
  6.  
  7. <Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="Thumb"
  8. x:Key="TestRoundThumb" <Setter Property="Template">
  9. <Setter.Value>
  10. <ControlTemplate TargetType="{x:Type Thumb}">
  11. <Ellipse Width="20" Height="15" Stroke="Blue"
  12. StrokeThickness="2"></Ellipse>
  13. </ControlTemplate>
  14. </Setter.Value>
  15. </Setter>
  16. </Style>
  17. </ResourceDictionary>
and here's the code in the button click event:
Expand|Select|Wrap|Line Numbers
  1. private void RoundThumb(object sender, RoutedEventArgs e)
  2. {
  3. Thumb roundThumb = new Thumb();
  4. roundThumb.Height = 15;
  5. roundThumb.Width = 20;
  6. roundThumb.Style = (Style)(this.Resources["TestRoundThumb"]);
  7. myGrid.Children.Add(roundThumb);
  8. }

"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:KZ******** ********@TK2MSF TNGHUB02.phx.gb l...
Thanks Keith. I hope you don't mind that I revised your code a little as
follows:

<Window x:Class="Window sApplication1.W indow1"
xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
Title="WindowsA pplication1" Height="300" Width="300"
>

<Thumb Height="10" Width="10" Opacity=".4" Background="Med iumBlue">
<Thumb.Style>
<Style TargetType="{x: Type Thumb}">
<Setter Property="Templ ate">
<Setter.Value >
<ControlTemplat e TargetType="{x: Type Thumb}">
<Ellipse Width="10" Height="5" Stroke="Blue"
StrokeThickness ="2"></Ellipse>
</ControlTemplate >
</Setter.Value>
</Setter>
</Style>
</Thumb.Style>
</Thumb>
</Window>

#Styling and Templating
http://msdn2.microsoft.com/en-us/library/ms745683.aspx
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.
Jan 10 '07 #4
As you may already have known, you could still define the style (template)
in XAML. Then you could use FindResource (method of FrameworkElemen t) to
load the resource and apply it to the Thumb object that you've created
using code:

<Grid Name="grid1">
<Grid.Resources >
<Style x:Key="ThumbSty le" TargetType="{x: Type Thumb}">
<Setter Property="Templ ate">
<Setter.Value >
<ControlTemplat e TargetType="{x: Type Thumb}">
<Ellipse Width="10" Height="5" Stroke="Blue" Fill="Blue"
StrokeThickness ="2"></Ellipse>
</ControlTemplate >
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Thumb Name="thumb1" Height="10" Width="10" Opacity=".4"
Background="Med iumBlue">
</Thumb>
</Grid>
Code:

thumb1.Style = (Style) grid1.FindResou rce("ThumbStyle ");

Hope this helps.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 12 '07 #5
Thanks Walter that did it. In my case I added the style to a resource file.
In order to refrence the style from c#, I had to add a reference to the file
in the window's xaml like this:

<Window.Resourc es>
<ResourceDictio nary Source="Diction ary1.xaml" />
</Window.Resource s>

Here's the style in Dictionary1.xam l:

<Style x:Key="ThumbSty le" TargetType="{x: Type Thumb}">
<Setter Property="Templ ate">
<Setter.Value >
<ControlTemplat e TargetType="{x: Type Thumb}">
<Ellipse Width="15" Height="15" Stroke="DarkSla teGray"
StrokeThickness ="0.5">
<Ellipse.Fill >
<SolidColorBrus h Color="DarkBlue " Opacity="0.2"></SolidColorBrush >
</Ellipse.Fill>
<Ellipse.Bitmap Effect>
<DropShadowBitm apEffect Color="Black" Direction="320"
ShadowDepth="5" Softness="0.5" Opacity="0.2" />
</Ellipse.BitmapE ffect>
</Ellipse>
</ControlTemplate >
</Setter.Value>
</Setter>
</Style>

and here's the c# that used it:

Thumb tb = new Thumb();
Canvas.SetLeft( tb, 100);
Canvas.SetTop(t b, 100);
myCanvas.Childr en.Add(tb);
tb.Style = (Style)this.Fin dResource("Thum bStyle");
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:a4******** ********@TK2MSF TNGHUB02.phx.gb l...
As you may already have known, you could still define the style (template)
in XAML. Then you could use FindResource (method of FrameworkElemen t) to
load the resource and apply it to the Thumb object that you've created
using code:

<Grid Name="grid1">
<Grid.Resources >
<Style x:Key="ThumbSty le" TargetType="{x: Type Thumb}">
<Setter Property="Templ ate">
<Setter.Value >
<ControlTemplat e TargetType="{x: Type Thumb}">
<Ellipse Width="10" Height="5" Stroke="Blue" Fill="Blue"
StrokeThickness ="2"></Ellipse>
</ControlTemplate >
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Thumb Name="thumb1" Height="10" Width="10" Opacity=".4"
Background="Med iumBlue">
</Thumb>
</Grid>
Code:

thumb1.Style = (Style) grid1.FindResou rce("ThumbStyle ");

Hope this helps.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 18 '07 #6
Hi moondaddy,

You probably have seen my reply in your another post regarding this
FindResource question. Anyway, I'm including the reply here again for your
reference:

-----------

When finding a resource, it first checks the current element's Resources
collection (its resource dictionary). If the item is not found, it checks
the parent element, its parent, and so on until it reaches the root
element. At that point, it checks the Resources collection on the
Application object. If it is not found there, it finally checks a system
collection (which contains system-defined fonts, colors, and other
settings). If the item is in none of these collections, it throws an
InvalidOperatio nException.

Therefore you could simply put resources in App.xaml within
<Application.Re sourcesand those resources will be shared by all your code
in the same assembly.

For ResourceDiction ary defined in separate .xaml files, you could use
following code to load it:

ResourceDiction ary rd = new ResourceDiction ary();
rd.Source = new Uri(@"Dictionar y1.xaml", UriKind.Relativ e);

Then you can use rd["resource_k ey"] to reference each resource.
-------------

Hope this helps.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 19 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9457
by: S.W. Rasmussen | last post by:
A trivial (?) question: does anyone know how to change the shape of the cursor in a RichTextBox control from the normal vertical line to an underscore?
2
2271
by: PA | last post by:
Hi, I want to implement the following in an applet: ^ | | + + + + + +H | + | + | H | +
0
1969
by: minjie | last post by:
Hello, I have several reports that were written with ADO shape command (in C++) to access Microsoft Access database. Now we have migrated all the data from Access to DB2 UDB (version 8.1), and the shape command does not work any more. I have changed the provider and connection string from: pConn->Provider = "MSDataShape"; SAFE_CALL( pConn->Open( "DBQ=myAccessDB.mdb; DefaultDir=.; Driver={Microsoft Access Driver (*.mdb)};", "sa", "", 0...
1
5182
by: AJ | last post by:
Hi guys, any clues or suggesstion on how to programatically change the shape of a button from rectangular to say elliptical or circular. Meaning that when the mouse hovers just within the shape, only then the Click event can be generated. Would be Great if you guys can help Code can be either in C# or VB.Net Thanx AJ
8
2447
by: Boni | last post by:
Dear all, imagine this is scroll bar. Min|-------------|scroller|---------|Max The position of scroller is set with Value. How do I change the width of scroller? Thank you in advance, Boni
2
4715
by: moondaddy | last post by:
I'm trying to do something real simple. Add a thumb to a grid at the end of a line using c#. the code executes but I dont see the thumb. Can anyone explain what and what I need to do to properly show the thumb? Here's the xaml for the window and the c# below. <Window x:Class="DragLineSample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
2
7478
by: mjrtom19 | last post by:
I have a Jframe using a menubar to determine the color and shape of a graphics2d object, at the moment the color stays red no matter what. I think the problem is in the itemListener in the inner class myShape, but I dont know what it is. Heres the code: import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.Graphics2D.*; import java.awt.geom.*;
1
3734
by: pankajprakash | last post by:
Hi, I have a word file which contains numbers of shapes. Each shape contain some textboxes. I am copying that file to another location and assigning some values to those textboxes of those shapes. Now I have to assign the values to those textboxes then I have to ungroup those shape first then only I can assign values those text boxes. Now the problem is that when I ungroup those shapes, they change their locations in the document. I do not...
0
1129
by: Bajwa | last post by:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; public class MyPolygonButton
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10609
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10105
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.