How can I achieve this blue background used in Skype when selecting a friend in the list? - winforms

I suppose it's some king of gradient used, but I can't tell.
I'd like to use the same in my WinForms application.

Easiest way to do something like this is to use a program like Paint.Net to get the RGB values of the colors used in the drawing.
Using a panel as an example:
void panel1_Paint(object sender, PaintEventArgs e) {
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (LinearGradientBrush br = new LinearGradientBrush(
panel1.ClientRectangle,
Color.FromArgb(52, 151, 254),
Color.FromArgb(61, 129, 243),
LinearGradientMode.Vertical)) {
e.Graphics.FillRectangle(br, panel1.ClientRectangle);
}
using (Pen p = new Pen(Color.FromArgb(37, 110, 184), 2)) {
e.Graphics.DrawRectangle(p, 0, 0,
panel1.ClientSize.Width - 1,
panel1.ClientSize.Height - 1);
}
}
Results in:
Pretty close to the original. You can make adjustments by lightening or darkening the colors used.

Related

Make PGraphic Object the cursor

This is a follow-up of my question: Make the cursor a self-drawn image.
I have a paint a picture application. The latest working version can be found here: https://knowledgeablekangaroo.github.io/paint-a-picture-backup/, where the code can be found in F12 > Sources > paint-a-picture.js.
The user can choose a color, set the background, set the thickness, shape, and opacity. There is also an eraser functionality. I want there to be a better user experience, so I am trying to draw the eraser below as the cursor. If the cursor doesn't work, I need something that doesn't smear.
The way I have programmed it, anywhere inside the "paint area" (above control center and below pallete) will smear - the background() is outside the draw.
var pg = createGraphics(pgDimensions.w, pgDimensions.h, JAVA2D);
pg.beginDraw();
pg.fill(255, 200, 255);
pg.strokeWeight(2);
pg.rect(0, 0, pgDimensions.w, pgDimensions.h);
pg.fill(0);
pg.textAlign(CENTER, CENTER);
pg.text("ERASER", pgDimensions.w / 2, pgDimensions.h / 2);
pg.endDraw();
I used the createGraphics() function to create a PGraphics Object. The point is to show the eraser while This shows the eraser I have drawn in the pGraphic above.
In the drawBrush() function, I make this an image.
var drawBrush = function() {
fill(currentColor);
noStroke();
shapes.forEach(function (element, index) {
if (pshape == index) {
element.brush();
}
});
if (C === bgColor) {
image(pg, mouseX - pgDimensions.w / 2, mouseY - pgDimensions.h / 2);
}
};
Research
This best describes my problem
After you have a graphics stored in your pg variable, you can draw that using the image() function:
image(pg, mouseX, mouseY);
Here's a small example that demonstrates what I'm talking about:
var pg;
function setup() {
createCanvas(400, 400);
pg = createGraphics(100, 100);
pg.ellipse(50, 50, 100, 100);
}
function draw() {
background(220);
image(pg, mouseX, mouseY);
}

Printing of DataGridView in Winform C#

I am trying to Printing Datagridview by making bitmap image , Its working nicely but it printing only in 1 page to print .
Here is DataGirdView Image :
Print Preview Image :
Here in print-Preview not having total rows to the last as of DataGridView row and only having 1 page
Code of Printing :
private void Btn_Print_Click(object sender, EventArgs e)
{
int height = DGV.Height;
DGV.Height = DGV.RowCount * DGV.RowTemplate.Height * 2;
bmp = new Bitmap(DGV.Width, DGV.Height);
DGV.DrawToBitmap(bmp, new Rectangle(0, 0, DGV.Width, DGV.Height));
DGV.Height = height;
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(bmp, 0, 0);
}
Why not printing data in more than 1 page ? Is there any wrong in code ? Please give suggestion
Thank you .
It's not the easiest thing to print multiple pages from a DataGridView so I recommend you to use one of the existing code samples. Here's couple good ones which are easy to use and can print multiple pages:
Another DataGridView Printer
DataGridView Print/Print Preview Solution
Some more examples are available from this SO question:
Best way to print a datagridview with all rows and all columns?

How to draw on System::Drawing::Graphics by a Timer Tick

I have Graphics^ g created on a PictureBox. I can draw on it inside events like MyForm_Load, Button_Click, but not in Timer_Tick. It doesn't draw anything:
System::Void timer1_Tick(...) {
g->Clear(Color::White);
Pen^ pen = gcnew Pen(Color::Black, 1);
g->DrawLine(pen, 10, 10, 30, 50); // of course values may change
}
How to solve the problem?
To show the drawing immediately, refresh an object which drawing is created on. For example, if drawing was created like g = Graphics::FromImage(pictureBox1->Image); use pictureBox1->Refresh();

Connecting two dynamically created shapes using line shape in silverlight

Im working on flowchart kind of application in asp.net using silverlight.. Im a beginner in Silvelight, Creating the elements (Rectangle,Ellipse,Line.. ) dynamically using SHAPE and LINE Objects in codebehind (c#)
These shapes will be generated dynamically, meaning I'll be calling a Web service on the backend to determine how many objects/shapes need to be created. Once this is determined, I'll need to have the objects/shapes connected together.
how to connect dynamically created shapes with a line in Silverlight like a flowchart.
I read the below article, but its not working for me, actualHeight & actualWidth of shapes values are 0.
Connecting two shapes together, Silverlight 2
here is my MainPage.xaml
<UserControl x:Class="LightTest1.MainPage">
<Canvas x:Name="LayoutRoot" Background="White">
<Canvas x:Name="MyCanvas" Background="Red"></Canvas>
<Button x:Name="btnPush" Content="AddRectangle" Height="20" Width="80" Margin="12,268,348,12" Click="btnPush_Click"></Button>
</Canvas>
code behind MainPage.xaml.cs
StackPanel sp1 = new StackPanel();
public MainPage()
{
InitializeComponent();
sp1.Orientation = Orientation.Vertical;
MyCanvas.Children.Add(sp1);
}
Rectangle rect1;
Rectangle rect2;
Line line1;
private void btnPush_Click(object sender, RoutedEventArgs e)
{
rect1 = new Rectangle()
{
Height = 30,
Width = 30,
StrokeThickness = 3,
Stroke = new SolidColorBrush(Colors.Red),
};
sp1.Children.Add(rect1);
rect2 = new Rectangle()
{
Height = 30,
Width = 30,
StrokeThickness = 3,
Stroke = new SolidColorBrush(Colors.Red),
};
sp1.Children.Add(rect2);
connectShapes(rect1, rect2);
}
private void connectShapes(Shape s1, Shape s2)
{
var transform1 = s1.TransformToVisual(s1.Parent as UIElement);
var transform2 = s2.TransformToVisual(s2.Parent as UIElement);
var lineGeometry = new LineGeometry()
{
StartPoint = transform1.Transform(new Point(1, s1.ActualHeight / 2.0)),
EndPoint = transform2.Transform(new Point(s2.ActualWidth, s2.ActualHeight / 2.0))
};
var path = new Path()
{
Data = lineGeometry,
Stroke = new SolidColorBrush(Colors.Green),
};
sp1.Children.Add(path);
}
what I am doing in button click event is just adding two rectangle shapes and tring to connect them with a line (like flowchart).
Please suggest what is wrong in my code..
Try replacing the line
connectShapes(rect1, rect2);
with
Dispatcher.BeginInvoke(() => connectShapes(rect1, rect2));
I'm not sure of the exact reason why this works, but I believe the shapes are only rendered once control passes out of your code, and only once they are rendered do the ActualWidth and ActualHeight properties have a useful value. Calling Dispatcher.BeginInvoke calls your code a short time later; in fact, you may notice the lines being drawn slightly after the rectangles.
The TransformToVisual method behaves in much the same way as the ActualWidth and ActualHeight properties. It will return an identity transformation if the shape hasn't been rendered. Even if your lines were being drawn with a definite width and height, they would end up being drawn all on top of one another at the top-left.
I also found that I needed to add the lines to the Canvas, not the StackPanel, in order for them to be drawn over the rectangles. Otherwise the StackPanel quickly filled up with lines with a lot of space above them.

Flip Horizontically Grid Background Image(Brush)

I have set a Grid's background brush as an ImageBrush.
But when I set the Grid's FlowDirection to RightToLeft, the image is flipped horizontically.
Is it possible to (un)flip the grid background ImageBrush using a certain Transition or any other way?
Not much you can do about that with sensible means (there same means that are far from sensible).
Instead place an Image element as the first item in the Grid with Grid.RowSpan, Grid.ColumnSpan to cover all the cells. Use Stretch="Fill" on the Image since thats how a background typically behaves.
Well, i do understand that my comment is outdated, but this question is popping up one of the first in Google search, so here is my solution:
I was localizing the application for the right-to-left culture. The simple decision to set FlowDirection=RTL comes with unexpected drawbacks like the background containing the company logo is flipped. I have applied the matrix transformation for the image brush used to render the background:
var mbgBrush = TryFindResource("MainBackground") as Brush;
if (mbgBrush == null) return null;
if (FlowDirection == FlowDirection.LeftToRight) return mbgBrush;
var mainBgImageBrush = mbgBrush as ImageBrush;
if (mainBgImageBrush == null) return mbgBrush;
var flipXaxis = new MatrixTransform(-1.0, 0, 0, 1.0, 1, 0);
var flippedBrush = new ImageBrush
{
Stretch = Stretch.None,
Opacity = 1.0,
ImageSource = mainBgImageBrush.ImageSource,
RelativeTransform = flipXaxis
};
return flippedBrush;

Resources