Looking for a way to create/replace custom controls + Border - c#

I'd like to create an application with exactly the same titlebar / controls as in Visual Studio. Or do you know dnSpy? It is using them as well.
https://prnt.sc/j731zj
I also like to have this 1px border, the blue one in this case.
I already googled alot, also tried to find something here, but I'm not finding anything helpful for me.
Here for example (it's from Wallpaper Engine) the window not only has that blue border, which I like to have, it has some kind of a blue shadow as well? Which looks pretty cool to me. I'd like to try that as well.
https://prnt.sc/j7321n
What I already tried in WinForms is working with panels and create it on my own.
https://prnt.sc/j73bj5
I managed to get the border that I want, I also could use pictureboxes for the min/max/close buttons?
But that's not exactly what I was looking for, I also have to code the move/drag behaviour of the app too then, since there is no controls anymore. Which is not that hard but... I want it another way.
Anyone can help me with that? I'm using C# in VS 2017 and I'd like to create the app either with Forms or WPF. Probably going for WPF.
Almost forgot to mention I don't really want to use 3rd party tools like MahApps, Metro Framework, etc.. Isn't there a build-in metro style option in VS or something? Rather in .NET framework.
I mean it's actually only these 3 buttons, min/max/close. And the border. That's all I need

It's quiet simple , if you wanna drag the window , make use of the DragMove method :
private void WhatEverControlYouWanttoUseToClickAndDrag_MouseDown()
{
DragMove();
)
The rest
You can simply use Image control.You can add any image you want to display.Put it above a Rectangle and use it.
Explanation
Image control comes from the System.Windows.Controls namespace.Rectangle control is no different.Now, you might ask ,why am i not suggesting Button ? Well, you can use a button but you cannot achieve your required looks with it unless you go with ControlTemplate,which,for a beginner, i would not suggest at all.
You can use a Rectangle,set a Fill color.Now, what if you want to change the color when the mouse is over the rect ? Well, here's a sample XAML that'll also add an animation to the color-changing :)
<Rectangle >
<Rectangle.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Fill" Value = "Blue" Duration="0:0:0.3"/>
///Add required closing tags please
Now, about the Image control.When you place it over the rectangle , you need to set the IsHitTestVisible property to False which will prevent any sort of mouse interaction on/with it which will also prevent the interference between the Image and the Rectangle. :)
One last tip , if you want to have the Image control apply the clearest look/best quality on the image,make sure to set BitmapScalingMode to Fant :
<Image Source="\ac.png" RenderingOptions.BitmapScalingMode="Fant"/>

Related

How to get back Visual Studio's old way of alerting of suggestions by darkening code instead of by 3 dots?

Visual Studio used to alert us of unused variables by darkening them. Now (version 16.10.2) it fills the code with three dots everywhere, which look a little like code and are more confusing.
Is there a way to get the old way back?
There is a color control for the ellipses called "Suggestion Ellipses...". You could set the foreground color of it to the same color as your editors background to get a sense that its turned off. You'll still see it when you select the item though like so:
Version 16.10.3 now
It looks like they changed it back.
So if you still have it - update VS.

How to create custom shaped Buttons in WPF?

(Before this gets marked as a duplicate, I'd like to say that I've tried the answers on other posts, but they don't seem to work for my specific issue.)
I'm creating a sort of "map game", where there's a map split into multiple areas. Currently, this is what I have:
It works, but it's not pretty. I want to make the buttons (currently they're the Rectangle control, but I can change that easily) the right shape.
I tried making a path in Inkscape, which gave me this SVG path:
m 283.60033,267.22114 11.61675,32.57742 14.14214,-8.33376 10.35406,-1.01015 11.61676,-5.3033 10.6066,-5.05077 0,-16.66751 -34.85027,-3.78808 -8.08122,2.77792 -14.64721,0.75762 z
However, when I tried to make a Button (and later Polygon) use the path, it didn't work and instead made a completely different shape.
The Buttons need to have a background color that can change during runtime, so a PictureBox won't work.
Is there a reason why the Path didn't work? Or maybe there is a much easier method?
EDIT: Here is the code I used for the Polygon
<Polygon Fill="Blue" Points="283.60033,267.22114 11.61675,32.57742 14.14214,-8.33376 10.35406,-1.01015 11.61676,-5.3033 10.6066,-5.05077 0,-16.66751 -34.85027,-3.78808 -8.08122,2.77792 -14.64721,0.75762" Margin="248,102,956,22" RenderTransformOrigin="0.5,0.5" Grid.ColumnSpan="2"/>
And here is the result, which is the same shape I got when I tried changing the shape of a Button (unfortunately I deleted the code for that):
Here is what it should look like (path drawn in Inkscape):
I figured it out and it was actually pretty easy! I actually didn't need Inkscape at all.
I imported the map image into Blend, and I traced the area with the Pen tool and made it into a Path, which I copied back into Visual Studio.
Example:
Are you sure you didn't get mixed up with which part you picked out the xaml inkscape produced?
Because that's roughly the top right part of the iberian peninsular. Like your drawn map. Roughly anyhow. That's just a polygon - with hard edges. Meaning however you produced it, you didn't trace the curvy/rough edges of what you're showing us.
Also.
If you look at the data that's in it.
See where it starts?
m 283.60033,267.22114
Those are x,y co-ordinates.
268px left, 267px down
From the top left corner of whatever container you put it in.
Is that going to work for you?

c# WPF Change the check color of a CheckBox

<CheckBox Background="White" IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}"/>
I need to change the color of the check. I figured Forground did this since Background changed the background color but to no avail.
Any ideas? Surly there is a way to directly change the check color. I tried googling this but the only solution I found was to make my own checkbox class.
Where is the property to change the CheckBox Check color?
I found one answer with
<Path Visibility="Collapsed"
Width="7"
Height="7"
x:Name="CheckMark"
SnapsToDevicePixels="False"
StrokeThickness="2"
Data="M 0 0 L 7 7 M 0 7 L 7 0">
<Path.Stroke>
<SolidColorBrush Color="{DynamicResource GlyphColor}" />
</Path.Stroke>
</Path>
But that does not work since I cannot add that as a child element. Even if it worked, it would change too much. All I want is a white background with a black checkmark. Grey on Grey is terrible looking. Isn't there a built in way to change the color?
Unfortunately, the WPF folks decided to make the checkbox a BEAST to deal with. The check itself is actually a "BulletChrome" control, if you study the template. Now, the problem is that the BulletChrome control is all written in C# and not customizable at all from the outside, not via XAML, so all the pens and brushes are hard-coded. You'll find with Reflector or IlSpy, that you are after the GlyphStroke and GlyphFill properties and those two properties clone internal hardcoded brushes.
I had to do the same thing you did, and I ended up just copying the entire class out using ILSpy and modifying it just to tweak a few things.
Not the answer you'd hoped for, but there isn't a way to override this control easily.
EDIT: well, you could modify the two brushes with reflection if you want. That's easier then copying the whole class out :).
Its a beast of a class, so... BulletChrome.cs = 2262 lines!
EDIT #2: btw, doing a quick 1 or 2 line hack will break the animations, so you need to go the correct route if you care about those :).
EDIT #3: don't forget there are quite a few states for the check mark. Hover, pressed, disabled, etc. and lots of animations and transitions. So anybody who gives you a quick answer doesn't understand how this control is put together.
This is as annoying as SledgeHammer said with the Bullet bs. basically, the brushes are hardcoded, so there isn't an easy solution.
That being said, Here is a quick 1 line hack. This doesn't break animations on my machine.
Though, as SledgeHammer pointed out, there are several different states. I'll leave it up to you to override which ones you need. This will do the basic check.
typeof(BulletChrome).GetRuntimeFields().Where(f => f.Name == "_commonCheckMarkFill").First().SetValue(null, new SolidColorBrush(Colors.Yellow));
You're also going to have to reference PresentationFramework.Aero and include using Microsoft.Windows.Themes;
Its worth pointing out, this will affect every CheckBox, and potentially (depending on which brushes you overwrite) RadioButton, so depending on your needs, YMMV. But it does what you asked for.

C# .net framework- border on only one side of the form

I am an inexperienced programmer , completely new to programming for windows .
I am writing a little program that I always wanted . Its being written using C# using .net framework. atleast thats what I think I am doing. All the talk about framework and .nets , windows forms , and win32 api has all got me really confused.. :(
anyways I have simple Form object.
Form f = new Form() ;
f.Text = "" ;
f.ControlBox =false ;
Now How to remove the all the borders on the form except one sides? As in, the side borders should go , but the top border should stay
FormBorderStyle doesn't have anything for this
Also how do you people solve such problems yourself , without asking ? look at others code ? read a a book ? any particular website ?
I have googled , but it didn't turn up nothing.
Gidday,
This is impossible, unfortunately - you can remove the whole border, though, and then draw your own on the form and use OnMouseDown, OnMouseUp and OnMouseMove to do your own dragging...
To solve such a problem myself, I would look at various different ways of verbally representing the problem (eg. "borderless form", "custom borders on winform", etc) and spend a bit of time Googling for it. As my boss wisely says, productivity isn't always about how much code you cut, it's also about what you can learn.
EDIT: As the popular expression goes, "Google knows all" - chances are that, if you spend a bit of time googling and you still can't find anything, then it probably hasn't been solved, or it's very very rare. Another way would be to invest in a few good books, e.g. Windows Forms programming (or even just Windows programming - it's incredibly useful to know about the underlying mechanics of Windows, and things like that are what help turn you into a great developer. A great programmer is good at coding, but a great developer is good at actually building useful software. :)
I assume you've tried FormBorderStyle.FixedSingle? This would display a form with a border at the top only.
Anyway, if that isn't the case you can set the forms Region.
Something like...
public static void HideBorders(Form form)
{
Rectangle newRegion = form.Bounds;
Rectangle formArea = form.Bounds;
Rectangle clientArea = form.RectangleToScreen(form.ClientRectangle);
formArea.Offset(form.Location);
newRegion.Offset(clientArea.X - formArea.X, 0);
newRegion.Width = clientArea.Width;
newRegion.Height = (clientArea.Y - formArea.Y) + clientArea.Height;
form.Region = new Region(newRegion);
}
As for how do you know what to do? All of the things you mentioned, help files, web forums, books. The main thing is practice, practice, practice. The more you do something the better you should become.
I don't think it's actually possible to do exactly what you describe, since the .NET Framework is just going to delegate the drawing of your Form's border and title bar to Windows itself, which doesn't have any option for what you describe AFAIK.
Instead, what I would do is use FormBorderStyle.None and then draw any window decorations (title bar, borders) you want manually.
A Google search for "borderless form C#" turns up these sites as the top three hits:
BorderLess Window (java2s.com)
Transparent borderless forms in C# (c-sharpcorner.com)
Draggable Form: Drag a Borderless Form by Clicking Anywhere on the Form (codeproject.com)

How do I create a colour that will match the current visual style?

For our winforms application, we've been asked to colour invalid cells in a DataGridView in a red colour. We need to find a red colour that matches the current visual style but which is still distinctive if the user has chosen a palette with mostly reds. How do I create a colour that will match the current visual style? How do I make sure I avoid clashes?
I don't think the original poster is looking to make a palette of colors (colours), instead he is trying to highlight an invalid cell. The chosen highlight color is red, but he is concerned that red might not stick out if the user has chosen a red palette.
How about this: When painting an invalid cell, use SystemColors.Window for the text and SystemColors.WindowText for the background. (or whatever equivalents there are for a DataGridView). This way, you are guaranteed that the invalid cell will be the opposite colors of a normal cell.
I think that you are looking at this the wrong way. Red is often chosen for several reasons. It is (in western culture among others) commonly used to depict that something is wrong or danger. But red is also a colour that usually stands out. However, when trying to direct a users attention to something on the page, there are two infallible methods.
1) Animated gifs or videos (annoying as f***) or
2) Clashing colours
Usually red stands out, but in your situation where a user may have a red themed style, your best bet is to go with a colour that will clash. It is possible to have clashing colours that go together (if that makes sense).
Here are a few websites that I have used in the past to help me find colour schemes that may help you as well:
Kuler, Color Combos and Color scheme designer
This may not have been the answer you were looking for but i hope it helps
The question is a bit ambiguous and a little subjective; it much easier to comment directly on examples. However, there are a multitude of on-line tools that will help you create colour palettes for websites, and these may be useful to gauge how a particular shade of red interacts with various other colours.
Hope this helps.
You could maybe try to use the Light and Dark methods of the ControlPaint class? I do something similar, although kind of in the opposite direction. I needed to make some rows in a grid stand out, but not stand out as much as the selected rows. So I created a color that was a bit lighter than the default selection color like this:
checkedColor = ControlPaint.Light(grid.DefaultCellStyle.SelectionBackColor, 1.65f);
Could try to use that, maybe with some added logic, and base it on some system color that is made to stand out. For example System.Drawing.SystemColors.HighLight or System.Drawing.SystemColors.HotTrack.
take a look at the Krypton Toolkit (http://www.componentfactory.com). They offer a free toolkit for WinForms controls with a theme manager. This theme manager provides ready to use methods to extract the current color values.
I have nothing to do with them. I use it for my own Product (Royal TS at http://www.code4ward.net) and found it really useful.
If you want to build beautiful UI, you should take a look at the Krypton stuff.

Categories