Skip to content
22 changes: 11 additions & 11 deletions docs/framework/winforms/advanced/how-to-create-a-path-gradient.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ The <xref:System.Drawing.Drawing2D.PathGradientBrush> class allows you to custom

- The following example fills an ellipse with a path gradient brush. The center color is set to blue and the boundary color is set to aqua. The following illustration shows the filled ellipse.

![Gradient Path](./media/pathgradient1.png "pathgradient1")
![Gradient Path fills an ellipse.](./media/how-to-create-a-path-gradient/gradient-path-filled-ellipse.png)

By default, a path gradient brush does not extend outside the boundary of the path. If you use the path gradient brush to fill a figure that extends beyond the boundary of the path, the area of the screen outside the path will not be filled.

The following illustration shows what happens if you change the <xref:System.Drawing.Graphics.FillEllipse%2A> call in the following code to `e.Graphics.FillRectangle(pthGrBrush, 0, 10, 200, 40)`.
The following illustration shows what happens if you change the <xref:System.Drawing.Graphics.FillEllipse%2A> call in the following code to `e.Graphics.FillRectangle(pthGrBrush, 0, 10, 200, 40)`:

![Gradient Path](./media/pathgradient2.png "pathgradient2")
![Gradient Path extended beyond boundary of the path.](./media/how-to-create-a-path-gradient/gradient-path-extended-beyond-boundary.png)

[!code-csharp[System.Drawing.UsingaGradientBrush#11](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/CS/Class1.cs#11)]
[!code-vb[System.Drawing.UsingaGradientBrush#11](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/VB/Class1.vb#11)]
Expand All @@ -40,9 +40,9 @@ The <xref:System.Drawing.Drawing2D.PathGradientBrush> class allows you to custom
[!code-csharp[System.Drawing.UsingaGradientBrush#12](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/CS/Class1.cs#12)]
[!code-vb[System.Drawing.UsingaGradientBrush#12](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/VB/Class1.vb#12)]

- The following example draws a path gradient without a <xref:System.Drawing.Drawing2D.GraphicsPath> object in the code. The particular <xref:System.Drawing.Drawing2D.PathGradientBrush.%23ctor%2A> constructor in the example receives an array of points but does not require a <xref:System.Drawing.Drawing2D.GraphicsPath> object. Also, note that the <xref:System.Drawing.Drawing2D.PathGradientBrush> is used to fill a rectangle, not a path. The rectangle is larger than the closed path used to define the brush, so some of the rectangle is not painted by the brush. The following illustration shows the rectangle (dotted line) and the portion of the rectangle painted by the path gradient brush.
- The following example draws a path gradient without a <xref:System.Drawing.Drawing2D.GraphicsPath> object in the code. The particular <xref:System.Drawing.Drawing2D.PathGradientBrush.%23ctor%2A> constructor in the example receives an array of points but does not require a <xref:System.Drawing.Drawing2D.GraphicsPath> object. Also, note that the <xref:System.Drawing.Drawing2D.PathGradientBrush> is used to fill a rectangle, not a path. The rectangle is larger than the closed path used to define the brush, so some of the rectangle is not painted by the brush. The following illustration shows the rectangle (dotted line) and the portion of the rectangle painted by the path gradient brush:

![Gradient](./media/gradient4.png "gradient4")
![Gradient portion painted by the path gradient brush.](./media/how-to-create-a-path-gradient/gradient-painted-path-gradient-brush.png)

[!code-csharp[System.Drawing.UsingaGradientBrush#13](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/CS/Class1.cs#13)]
[!code-vb[System.Drawing.UsingaGradientBrush#13](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/VB/Class1.vb#13)]
Expand All @@ -59,7 +59,7 @@ The <xref:System.Drawing.Drawing2D.PathGradientBrush> class allows you to custom

The following illustration shows the output of the following code. The ellipse on the left is aqua only at the center point. The ellipse on the right is aqua everywhere inside the inner path.

![Gradient](./media/focusscales1nogamma.png "focusscales1NoGamma")
![Gradient effect of focus scales](./media/how-to-create-a-path-gradient/focus-scales-aqua-inner-outer-ellipse.png)

[!code-csharp[System.Drawing.UsingaGradientBrush#14](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/CS/Class1.cs#14)]
[!code-vb[System.Drawing.UsingaGradientBrush#14](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/VB/Class1.vb#14)]
Expand All @@ -72,7 +72,7 @@ The <xref:System.Drawing.Drawing2D.PathGradientBrush> class allows you to custom

The following illustration shows the triangle filled with the custom path gradient brush.

![Gradient Path](./media/pathgradient4.png "pathgradient4")
![Triangle filled with custom path gradient brush.](./media/how-to-create-a-path-gradient/gradient-brush-filled-triangle.png)

[!code-csharp[System.Drawing.UsingaGradientBrush#15](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/CS/Class1.cs#15)]
[!code-vb[System.Drawing.UsingaGradientBrush#15](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/VB/Class1.vb#15)]
Expand All @@ -86,18 +86,18 @@ The <xref:System.Drawing.Drawing2D.PathGradientBrush> class allows you to custom
[!code-csharp[System.Drawing.UsingaGradientBrush#16](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/CS/Class1.cs#16)]
[!code-vb[System.Drawing.UsingaGradientBrush#16](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/VB/Class1.vb#16)]

The following illustration shows the filled ellipse and the center point of the path gradient brush.
The following illustration shows the filled ellipse and the center point of the path gradient brush:

![Gradient Path](./media/pathgradient5.png "pathgradient5")
![Gradient Path with filled ellipse and center point.](./media/how-to-create-a-path-gradient/gradient-path-filled-ellipse-center-point.png)

- You can set the center point of a path gradient brush to a location outside the path that was used to construct the brush. The following example replaces the call to set the <xref:System.Drawing.Drawing2D.PathGradientBrush.CenterPoint%2A> property in the preceding code.

[!code-csharp[System.Drawing.UsingaGradientBrush#17](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/CS/Class1.cs#17)]
[!code-vb[System.Drawing.UsingaGradientBrush#17](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.UsingaGradientBrush/VB/Class1.vb#17)]

The following illustration shows the output with this change.
The following illustration shows the output with this change:

![Gradient Path](./media/pathgradient6.png "pathgradient6")
![Gradient Path with center point outside the path.](./media/how-to-create-a-path-gradient/gradient-path-center-point-outside.png)

In the preceding illustration, the points at the far right of the ellipse are not pure blue (although they are very close). The colors in the gradient are positioned as if the fill reached the point (145, 35) where the color would be pure blue (0, 0, 255). But the fill never reaches (145, 35) because a path gradient brush paints only inside its path.

Expand Down
16 changes: 8 additions & 8 deletions docs/framework/winforms/advanced/how-to-rotate-colors.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ ms.assetid: e2e4c300-159c-4f4a-9b56-103b0f7cbc05
# How to: Rotate Colors
Rotation in a four-dimensional color space is difficult to visualize. We can make it easier to visualize rotation by agreeing to keep one of the color components fixed. Suppose we agree to keep the alpha component fixed at 1 (fully opaque). Then we can visualize a three-dimensional color space with red, green, and blue axes as shown in the following illustration.

![Recoloring](./media/recoloring03.gif "recoloring03")
![Illustration that shows rotation with red, green, and blue axes.](./media/how-to-rotate-colors/rotation-red-green-blue-axes.gif)

A color can be thought of as a point in 3-D space. For example, the point (1, 0, 0) in space represents the color red, and the point (0, 1, 0) in space represents the color green.

The following illustration shows what it means to rotate the color (1, 0, 0) through an angle of 60 degrees in the Red-Green plane. Rotation in a plane parallel to the Red-Green plane can be thought of as rotation about the blue axis.

![Recoloring](./media/recoloring04.gif "recoloring04")
![Illustration that shows rotation about the blue axis.](./media/how-to-rotate-colors/rotation-about-blue-axis.gif)

The following illustration shows how to initialize a color matrix to perform rotations about each of the three coordinate axes (red, green, blue).
The following illustration shows how to initialize a color matrix to perform rotations about each of the three coordinate axes (red, green, blue):

![Recoloring](./media/recoloring05.gif "recoloring05")
![Initialize a color matrix to perform rotations about three axes.](./media/how-to-rotate-colors/rotation-about-three-axes.gif)

## Example
The following example takes an image that is all one color (1, 0, 0.6) and applies a 60-degree rotation about the blue axis. The angle of the rotation is swept out in a plane that is parallel to the red-green plane.

The following illustration shows the original image on the left and the color-rotated image on the right.
The following illustration shows the original image on the left and the color-rotated image on the right:

![Rotate Colors](./media/colortrans5.png "colortrans5")
![Illustration that shows original image and color-rotated image.](./media/how-to-rotate-colors/original-color-rotated-images.png)

The following illustration shows a visualization of the color rotation performed in the following code.
The following illustration shows a visualization of the color rotation performed in the following code:

![Recoloring](./media/recoloring06.gif "recoloring06")
![Illustration that shows the visualization of the color rotation.](./media/how-to-rotate-colors/visualization-color-rotation.gif)

[!code-csharp[System.Drawing.RotateColors#1](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.RotateColors/CS/Form1.cs#1)]
[!code-vb[System.Drawing.RotateColors#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.RotateColors/VB/Form1.vb#1)]
Expand Down
10 changes: 5 additions & 5 deletions docs/framework/wpf/advanced/threading-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ms.assetid: 02d8fd00-8d7c-4604-874c-58e40786770b

Consider the following example:

![Prime numbers screen shot](./media/threadingprimenumberscreenshot.PNG "ThreadingPrimeNumberScreenShot")
![Screenshot that shows threading of prime numbers.](./media/threading-model/threading-prime-numbers.png)

This simple application counts upwards from three, searching for prime numbers. When the user clicks the **Start** button, the search begins. When the program finds a prime, it updates the user interface with its discovery. At any point, the user can stop the search.

Expand All @@ -68,7 +68,7 @@ ms.assetid: 02d8fd00-8d7c-4604-874c-58e40786770b

The best way to split processing time between calculation and event handling is to manage calculation from the <xref:System.Windows.Threading.Dispatcher>. By using the <xref:System.Windows.Threading.Dispatcher.BeginInvoke%2A> method, we can schedule prime number checks in the same queue that [!INCLUDE[TLA2#tla_ui](../../../../includes/tla2sharptla-ui-md.md)] events are drawn from. In our example, we schedule only a single prime number check at a time. After the prime number check is complete, we schedule the next check immediately. This check proceeds only after pending [!INCLUDE[TLA2#tla_ui](../../../../includes/tla2sharptla-ui-md.md)] events have been handled.

![Dispatcher queue illustration](./media/threadingdispatcherqueue.PNG "ThreadingDispatcherQueue")
![Screenshot that shows the dispatcher queue.](./media/threading-model/threading-dispatcher-queue.png)

[!INCLUDE[TLA#tla_word](../../../../includes/tlasharptla-word-md.md)] accomplishes spell checking using this mechanism. Spell checking is done in the background using the idle time of the [!INCLUDE[TLA2#tla_ui](../../../../includes/tla2sharptla-ui-md.md)] thread. Let's take a look at the code.

Expand Down Expand Up @@ -103,7 +103,7 @@ ms.assetid: 02d8fd00-8d7c-4604-874c-58e40786770b

In this example, we mimic a remote procedure call that retrieves a weather forecast. We use a separate worker thread to execute this call, and we schedule an update method in the <xref:System.Windows.Threading.Dispatcher> of the [!INCLUDE[TLA2#tla_ui](../../../../includes/tla2sharptla-ui-md.md)] thread when we’re finished.

![Weather UI screen shot](./media/threadingweatheruiscreenshot.PNG "ThreadingWeatherUIScreenShot")
![Screenshot that shows the weather UI.](./media/threading-model/threading-weather-ui.png)

[!code-csharp[ThreadingWeatherForecast#ThreadingWeatherCodeBehind](~/samples/snippets/csharp/VS_Snippets_Wpf/ThreadingWeatherForecast/CSharp/Window1.xaml.cs#threadingweathercodebehind)]
[!code-vb[ThreadingWeatherForecast#ThreadingWeatherCodeBehind](~/samples/snippets/visualbasic/VS_Snippets_Wpf/ThreadingWeatherForecast/visualbasic/window1.xaml.vb#threadingweathercodebehind)]
Expand Down Expand Up @@ -183,7 +183,7 @@ ms.assetid: 02d8fd00-8d7c-4604-874c-58e40786770b
### Nested Pumping
Sometimes it is not feasible to completely lock up the [!INCLUDE[TLA2#tla_ui](../../../../includes/tla2sharptla-ui-md.md)] thread. Let’s consider the <xref:System.Windows.MessageBox.Show%2A> method of the <xref:System.Windows.MessageBox> class. <xref:System.Windows.MessageBox.Show%2A> doesn’t return until the user clicks the OK button. It does, however, create a window that must have a message loop in order to be interactive. While we are waiting for the user to click OK, the original application window does not respond to user input. It does, however, continue to process paint messages. The original window redraws itself when covered and revealed.

![MessageBox with an "OK" button](./media/threadingnestedpumping.png "ThreadingNestedPumping")
![Screenshot that shows a MessageBox with an OK button](./media/threading-model/threading-message-loop.png)

Some thread must be in charge of the message box window. [!INCLUDE[TLA2#tla_winclient](../../../../includes/tla2sharptla-winclient-md.md)] could create a new thread just for the message box window, but this thread would be unable to paint the disabled elements in the original window (remember the earlier discussion of mutual exclusion). Instead, [!INCLUDE[TLA2#tla_winclient](../../../../includes/tla2sharptla-winclient-md.md)] uses a nested message processing system. The <xref:System.Windows.Threading.Dispatcher> class includes a special method called <xref:System.Windows.Threading.Dispatcher.PushFrame%2A>, which stores an application’s current execution point then begins a new message loop. When the nested message loop finishes, execution resumes after the original <xref:System.Windows.Threading.Dispatcher.PushFrame%2A> call.

Expand All @@ -203,7 +203,7 @@ ms.assetid: 02d8fd00-8d7c-4604-874c-58e40786770b

Most interfaces are not built with thread safety in mind because developers work under the assumption that a [!INCLUDE[TLA2#tla_ui](../../../../includes/tla2sharptla-ui-md.md)] is never accessed by more than one thread. In this case, that single thread may make environmental changes at unexpected times, causing those ill effects that the <xref:System.Windows.Threading.DispatcherObject> mutual exclusion mechanism is supposed to solve. Consider the following pseudocode:

![Threading reentrancy diagram](./media/threadingreentrancy.png "ThreadingReentrancy")
![Diagram that shows threading reentrancy.](./media/threading-model/threading-reentrancy.png "ThreadingReentrancy")

Most of the time that’s the right thing, but there are times in [!INCLUDE[TLA2#tla_winclient](../../../../includes/tla2sharptla-winclient-md.md)] where such unexpected reentrancy can really cause problems. So, at certain key times, [!INCLUDE[TLA2#tla_winclient](../../../../includes/tla2sharptla-winclient-md.md)] calls <xref:System.Windows.Threading.Dispatcher.DisableProcessing%2A>, which changes the lock instruction for that thread to use the [!INCLUDE[TLA2#tla_winclient](../../../../includes/tla2sharptla-winclient-md.md)] reentrancy-free lock, instead of the usual [!INCLUDE[TLA2#tla_clr](../../../../includes/tla2sharptla-clr-md.md)] lock.

Expand Down