how to create triangular button in c# - c#-3.0

How to create Custom shaped buttons in c#: say triangular

You could use a pictureBox as a button.

Easiest way is to set a tringular image on the button, with transparent areas outside the triangle.
As others have suggested, you could also use a PictureBox object as a button and handle the "click" even of it.
Another way is probably to write a TriangleButton class that extends the Button class, then override the Paint method so that you can draw a triangle instead of the regular button shape. Not sure how to handle the "click" areas of the button (you might still have a a rectangular click region).

You create a rectangular ImageButton with a transparent background.

Related

Codename One Drag and Drop - Target change background color on Drag Over

I have an Android application with some draggable elements.
There are some some labels that I want do drag over containers. The moment I drag over the container, I want the container background to change its colour.
I am unable to achieve this with DragOverListener from the API.
This is my code:
label.addDragOverListener(l -> {
container.getAllStyles().setBgColor(ColorUtil.YELLOW);
container.getAllStyles().setBgTransparency(255);
});
What happens is that as soon as I start dragging the label, the container changes the colour. But that's not what I want. I want the container to change the colour only when I drag over it.
Is there a way to achieve this?
Many thanks in advance.
The event delivers an X/Y location for the drag which you can use to determine whether to draw the color or not. Generally, this API is designed for refined drawing of this type e.g. drawing a square in the place the dropped component will occupy.

Oddly shaped buttons

How can I set an image as a button but have the boundaries of the image be the boundaries of the button as well? i.e. a trapezoid that appears on the users screen but the user can only click within the trapezoid.
I know this exists in Objective C as OBShapedButton but I would like to do the same using swift.
Thanks so much

How to change the shape of a UIButton in Swift?

I am trying to make an arrow shape. I understand that it will be done with CGRect method but can you give a complete example of how it will be done in SWIFT?
This can be done programmatically by first subclassing UIButton and overriding drawRect within it to form the shape of an arrow via bezier paths. Then simply set the title of the button to be whatever you want your text to be and position it accordingly within the shape you have drawn.
The benefit of doing it this way is that you can easily change the color of, scale and dimensions of the arrow since you control how the object is actually being drawn.
A good tool for drawing complex bezier paths is paintCode. I'm using the trial version and can pretty easily make shapes like this now.

Custom Non Rectangular Buttons Triangular shape

I want to use triangle type buttons on image but i am unable to do this...
How to do this?
This project can help you. you can customize the shape of the UIButton.
All UIViews - all of them - are rectangles. You cannot make a UIView that is a triangle, but you can make one that contains and presents a triangular shape and responds only to touches within that shape. You must understand of course that underneath it all, it's a rectangle, and you'll have to handle the case wherein the user touches outside of the triangle but inside of the rectangle, probably by passing such events through to views below. Indeed, you might have to handle all touch event combinations (touch down inside, touch up outside, touch move outside, etc) in this way.
Maybe the project referenced above will handle all this, I didn't look too deeply.

How to extend a button touch area?

I have an arrow button that I want to keep small but I want the touch area around it to be bigger.
I used the answer from the post Here but it made my button larger.
The problem is that the picture of the button is larger than the size it is presented in. But I thought there must be a way to do it without editing it or adding a transparent button.
Use a custom button with an image with mode "center"(which means that it doesn't resize with the button size and stays always in the center). Then you can make the button as big as you want and the button image always stays in the middle with the same size.
You should be able to do it by extending the button class and overriding the hitTest method. In your version of this method you can expand the area checked to include a buffer area and return the button if the touch happens within it.
A transparent button behind this button would also work and just point that to the method... I suppose you could go about this multiple ways. One should prefer the option that is simplest with the least overhead.