vb.net,winforms,button,picturebox,fade , VB.NET Fading out button properly

VB.NET Fading out button properly


Tag: vb.net,winforms,button,picturebox,fade

How do you fade out/in a button in VB.NET properly? I can fadeout/in labels using:

Controls(i).ForeColor = Color.FromArgb(255, alpha, alpha, alpha)

(where Controls(i) is a label from a For Next loop through all controls in Me.Controls; alpha is the value of the RGB, also from a For Next loop).

This did not work for me with buttons because changing the ForeColor leaves the rest of the buttons' UIs visible!

So, the way I'm trying uses a saved Resource image of the button (from a screenshot) and creates a faded in/out version to be displayed as the image in a PictureBox:

Public Function SetImageOpacity(ByVal imgPic As Image, ByVal imgOpac As Double) As Image
    Dim bmpPic As New Bitmap(imgPic.Width, imgPic.Height)
    Dim grPic As Graphics = Graphics.FromImage(bmpPic)
    Dim imgAtt As New ImageAttributes()
    Dim cmxPic As New ColorMatrix()
    cmxPic.Matrix33 = imgOpac
    imgAtt.SetColorMatrix(cmxPic, ColorMatrixFlag.[Default], ColorAdjustType.Bitmap)
    grPic.DrawImage(imgPic, New Rectangle(178, 144, bmpPic.Width, bmpPic.Height), imgPic.Width, imgPic.Height, imgPic.Width, imgPic.Height, GraphicsUnit.Pixel, imgAtt)
    Return bmpPic
End Function

(where imgPic is the Resource image of the button, and imgOpac is the opacity on a scale of 1 to 0, where 0 is transparent).

I then use this image to set my PictureBox's image:

picbox.Image = SetImageOpacity(My.Resources.Nextbutton, 1)

However, I get a glitch where, even though the PictureBox is located at coordinates 178, 144, the image it is showing is displayed at the left edge of the form (i.e. wrong X coordinate), with the Y coordinate correct!

I have a feeling it may lie with my call of .DrawImage(...) (at line 8 of the function) - but the MSDN docs on this subject are very unclear to me.

Please link if this has been asked before!


The coordinates in the Graphics grPic are client coords relative to the image itself, not the Form. So (0, 0) is the top left of the image regardless of where that image ends up being displayed in some kind of control.

Try changing it to (0, 0):

grPic.DrawImage(imgPic, New Rectangle(0, 0, bmpPic.Width, bmpPic.Height), imgPic.Width, imgPic.Height, imgPic.Width, imgPic.Height, GraphicsUnit.Pixel, imgAtt)


How to make existing forms deriven from a base form in VB.net

I have an existing project in VB.net with many Windows forms.I want to change all forms to deriven from a base form created in a class library. is there any way to do so? if i do inheritance with a code like this the designer dose not show the child...

Updating a list of objects bound to a DataGridView from a popup form

I seem to be having a bit of a problem with returning the updated information on my edit button placed on the popup form, back to my DataGridView (which is bound to a list of objects) on the original form. I seemed to have it working the other day, however,...

How to make inherited form full screen [on hold]

I am having some trouble trying to get a windows form project go full screen and to hide the taskbar. I am inheriting forms from a master form. When I add the following code it still shows the task bar at the bottom. this.TopMost = true; this.FormBorderStyle = FormBorderStyle.None; this.WindowState...

Regex to check if string is alphanumeric separated by commas or a single alphanumeric string

I have the following right now which works fine if the string is alphanumeric and separated by commas, but it doesn't work if I only have a single string. "^([a-zA-Z0-9]+,)+[a-zA-Z0-9]+$" Works for something like "1A,1B,1C", doesn't work on "1A" Sorry, I don't know much about regex and I only got...

Gridview items not populating correctly

I have data I am trying to input into a gridview. I am looking up the number of rows for the gridview and adding data into them like this: My "test" however does not get populated into the Submitted and Variance BoundFields in the Gridview. All that populates is the...

How to pass all value of ListBox Control to a function?

I am writing a simple application to read the value a textbox and add to a listbox control . But i have to pass the listbox control to function . Any suggestion ? Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load test("E:\Satyajit.txt") End Sub Public Function...

Set Label From Thread

Form1.vb Imports System.Threading Public Class Form1 Dim demoThread As Thread Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim Start As New Class1 Me.demoThread = New Thread( _ New ThreadStart(AddressOf Start.ThreadProcSafe)) Me.demoThread.Start() End Sub Delegate Sub SetTextCallback([text] As String) Public Sub SetText(ByVal [text] As String) ' InvokeRequired required...

Custom Numericupdown

I'm trying to create a custom numericUpDown control. I'm trying to add text to the numericUpDown and I got it working good. But, now I want to find a way to select only the number when clicking in the control, because at this moment when I "edit" the value manually,...

vb.net AES decryption returns “data is incomplete block”

I'm aware of the other thread on this issue (AES decryption error " The input data is not a complete block." Error vb.net), but I'm either not implementing the solutions offered there correctly, or something about my particular variant of this issue isn't covered by those solutions. In any event...

check if a list contains all the element in an array using linq

I have a list of objects and I have an array of keywords. I need to check if all the elements of the array are present inside the list of objects. The user enters the data to be searched like this pain+fever+thirst+itching My code looks like: //i check if the...

How can i get list of my youtube videos from youtube?

I installed the google api 3 and the OAuth2. And i tried the google develope example: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Google.GData.Client; using Google.GData.Extensions; using Google.GData.YouTube; using Google.GData.Extensions.MediaRss; using Google.YouTube; namespace Youtube_Manager { public partial class...

Move windows form from a picturebox in C#

I have a windows form without any border. So i added a picture box and i want the whole form to be moved when that picture box is clicked. public const int WM_NCLBUTTONDOWN = 0xA1; public const int HT_CAPTION = 0x2; [DllImportAttribute("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg,...

Scraping Javascript webpage (script error occurred)

I am scraping a dynamic webpage which is a javascript based webpage. I have done codes which is used to load the webpage first in the program: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load WebBrowser1.Navigate("http://www.changiairport.com/flight-info/flight-status/passenger-departures") End Sub However, each time I run the program, script...

Removing Alert When Using DeleteFile API

I'm writing a VBA application which involves looping a large number of directories recursively. I am using the FindFirstFile API to to achieve this, as it offers a substantial performance boost over the FileSystemObject. In order to remove the FSO from my code entirely, I need a routine to delete...

How to create a folder that contains the current date and time instead of name

I use C++ Windows Form application in Visual Studio 2013 for one project. I wonder how to create a folder that contains the current date and time instead of name? It is possible to make such folder?? DirectoryInfo^ directory = Directory::CreateDirectory("C:\Users\Desktop\" + ??); ...

VB.Net DateTime conversion

I have a jquery datepicker in a usercontrol. On the usercontrol i have a property that will return the selected date to the page which contains my usercontrol. I try to convert the string to a date: Dim MyDate As System.DateTime = System.Convert.ToDateTime(txtFromDateF.Value, System.Globalization.DateTimeFormatInfo.InvariantInfo) i keep getting the error: String...

Get List of Elements in Tree with specific Field Value

I have an Interface like this: Public Interface TreeSelectorAttributes Property selectedInTreeSelector As Boolean Property Name As String ReadOnly Property childs As IEnumerable(Of TreeSelectorAttributes) End Interface and I have a TreeView which has a List of this TreeSelectorAttributes: Public Property rootList As IEnumerable(Of TreeSelectorAttributes) now after the User chooses which elements...

ZipEntry() and converting persian filenames

In my vb.net project I'm trying to add a file with a Persian name to a zip file and I do this with the code bellow: Dim myentry As New ZipEntry(dr.Item("MyFile").ToString()) zipOut.PutNextEntry(myentry) however when I open the zip file I see the file name is changed to a gibberish Is...

Connecting to database using Windows Athentication

I would like to use window authentication in my program to connect to my sql server. users already have certain permissions on the SQL server and I would like to leverage that in my program. The way I currently connect to the server is using this connection string. Dim ConnectionString...

Managing per form ObjectContext lifetime

For ORMs like EF and NHibernate, multiple places suggest using "context per method" (or per request, per transaction) for web apps and services and using "context per form" for thick clients like WinForms and WPF. In C#, resource disposal with context per method is clean and clear with a using...

how can i use parameters to avoid sql attacks

I have a project without any parameters used in SQL queries. Is there any solution so that i don't have to change the function and validate parameters from the Query string itself? Query = "select * from tbl_Users where userName='"& textbox1.text &"' and password='"& textbox2.text &"' " ds = obj.ExecuteQueryReturnDS(Query)...

How can i put formclosing event in Button

i make this button btnCallenge and i want if the person click on it the form can't be closed if he try to close it i want the form cant be closed if the user click on chellange button public void btnChallenge_Click(object sender, EventArgs e) { } private void Form1_FormClosing(object...

How to use XDocument to get attributes and add them to a List

I am trying to load data from an XML file and add it to a List. The XML file looks like this: and this is my code: public void LoadPayments(List<List<string>> list1, List<List<string>> list2) { try { if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RentData.xml"))) { int count = 0; XDocument doc; using (var reader =...

getting keyboard input in winform listbox

i am altering a program so that a listbox picks up keyboard input (number pad, D0-D9, letter keys) and edits properties of the currently selected listbox item based on the input. my problem is that there seems to be no functionality that can convert a key press into a letter....

Retrieve full path of FTP file on drag & drop?

I can read the filename using next code when dragging a file from an Ftp folder browsed on Windows explorer. But is there a way to retrieve the full Ftp path? Private Sub DataGridView1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop Dim filename As String = "" If e.Data.GetDataPresent("UniformResourceLocator") Then...

Where to store an mp4 file in my project?

I have been studying vb.net for a couple of months now and I want to try something new. I have this sample project to try. It is a web browser and I want that if a button will be clicked, a video will play immediately. This is what my application...

How to execute four queries once and then check success or failure?

I need to execute four queries and then if there is success must return true otherwise false. The queries affect the database but the function returns false Private Function save_to_data() Dim success As Boolean = False Dim conn As OleDbConnection = GetDbConnection() Dim total_due As Decimal = sanitize(txt_total_due.Text) Dim amount_paid...

How do I use VB.NET to send an email from an Outlook account?

I'm trying to send an email via an outlook email account through a vb.net program. When I run the code I get an error telling me that I don't have a secure connection. I've been searching online and have tried all the adjustments I've found but I'm still not having...

VB.net: How to define a namespace where the first segment is NOT the file name?

Suppose I have a project called FooProject with a file called FooModel.vb which contains the following interfaces: Namespace Foo.Model Public Interface Foo ' ... End Interface Public Interface Bar ' ... End Interface End Namespace When I output this to a class library and import the DLL, the namespace I...

Get XML node value when previous node value conditions are true (without looping)

Sample XML - <?xml version="1.0"?> <Root> <PhoneType dataType="string"> <Value>CELL</Value> </PhoneType> <PhonePrimaryYn dataType="string"> <Value>Y</Value> </PhonePrimaryYn> <PhoneNumber dataType="string"> <Value>555-555-5554</Value> </PhoneNumber> <PhonePrimaryYn dataType="string"> <Value>Y</Value> </PhonePrimaryYn> <PhoneType dataType="string"> <Value>HOME</Value> </PhoneType>...

Visual Basic Datagrid View change row colour

Every other change to the datagrid view works fine but for some reason the row color just wont change. Ive debugged and my application goes through the loop to change the row color. Also I have a button that gives the datagrid view a new list and colors the rows...

Return index of word in string

This code: Module Module1 Sub Main() ' Our input string. Dim animals As String = "cat, dog, bird" ' See if dog is contained in the string. If Not animals.IndexOf("dog") = -1 Then Console.WriteLine(animals.IndexOf("dog")) End If End Sub End Module Return start position 5 in string But how to return...

Automapper AfterMap function initialising classes

Can anyone please explain how does the AfterMap function initalises the class objects passed in the lambda expression? When i run this bit of code as myself, it populates the dest object with my details. i can't figure out how is it doing that? but if someone can tell me...

Why does this code to replace accented chars with html codes fail to work?

I want to replace accented chars (such as á, ñ, ¿, ¡, etc.) with the corresponding HTML codes (such as á, ñ, ¿, ¡, etc.). For example, this line of text: Imposible me ha sido rehusarme á las repetidas instancias que el Caballero Trelawney, el Doctor Livesey y otros muchos...

VBMath using / equivalent in C# [closed]

I want to use something like VBMath.Randomize(); and VBMath.Rnd(); In C#, I tried with using Microsoft.VisualBasic; But this doesn't work...

Filtering Last Duplicate Occurrence In A Datatable

I am sorting a datable with the following code.. Dim sortedExtRecords1 As DataTable sortedExtRecords1 = parsedDataset.Tables("Detail").Clone Dim dvParsedDataset1 As New DataView(parsedDataset.Tables("Detail")) dvParsedDataset1.Sort = AuthorizatonConstants.Authorization_ID sortedExtRecords1 = dvParsedDataset1.ToTable("Detail") I can further filter the results to only return non duplicates and if there is duplicates I want the last record of the...

Convert Double from String

When converting string to floating, the converter creates wrong results. ?Global.System.Convert.ToDouble("635705821821928755").ToString("0") "635705821821929000" ?Global.System.Convert.ToSingle("635705821821928755").ToString("0") "635705800000000000" I am working with VB.Net Visual Studio 2012, Framework 4 on ASP.Net Webpage. Is there any solution for converting huge numbers from string into floating?...

DialogBox with value verifications

For my application which deals with graphics, I've made a little DialogBox to set: Max; Min; Major Step (of the scale); Minor Step. Here's a screen capture: I want to validate a few things before allowing the user to click Ok: Max >= Min MaxScale >= MinScale. But it's not...

Custom drawing using System.Windows.Forms.BorderStyle?

I want to mimick drawing of default border based on value of property BorderStyle. Instead of single border around the control, my control is visualised as four adjacent custom-drawn boxes (2×2), each having standard border drawn individually. So for example, if Control.Border is set to FixedSingle value I want to...

C# Windows Form Application - value not printing in textbox for each time

Value not printing in textbox for each time.. Iam able to see last value only (10) in textbox. private void button1_Click(object sender, EventArgs e) { for(int i = 0; i<=10; i++) { textBox1.Text = i.ToString(); Thread.Sleep(100); } } ...

Comparing arrays with numbers in vb.net

I need a way to compare two arrays in vb.net and save result in third array: Dim KonRes(3) As Integer Dim UserRes(3) As Integer Dim YelRed(3) As Integer KonRes(0) = 1 KonRes(1) = 2 KonRes(2) = 3 KonRes(3) = 4 UserRes(0) = 4 UserRes(1) = 3 UserRes(2) = 2 UserRes(3)...

NullReference Error while assiging values of Modeltype in MVC View (Razor)

I have the following MVC Model: Public Class Employee Public Property EmployeeID As Integer End Class Controller: Namespace Controllers Public Class EmployeeController Inherits Controller Function Details() As ActionResult Dim employee As Employee employee = New Employee employee.EmployeeID = 101 Return View() End Function End Class End Namespace View: @ModelType MVCDemo.Employee...

Convert date to string format

I have successfully imported data from xls into dataGridView. The date column in dataGridView is showing the DateTime format. I want this date column to be displayed in "dd MMM yyyy" format. I have tried as shown below: connExcel.Open() Dim dtExcelSchema As DataTable dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing) Dim SheetName As...

Can't output Guid Hashcode

I'm trying to use the hashcode of a guid as a random voucher name for a website, and have been trying to write new records to a SQL table with the Hashcode variable but it doesn't work. command.Parameters.Add("@voucherName", SqlDbType.NVarChar) command.Parameters("@voucherName").Value = Guid.NewGuid().GetHashCode() When using that code it just puts a...

Application is missing required files

Pic of Error: http://s23.postimg.org/7uj6qcxtn/9708083373e57a9ec91e4296e302f88e.png Cannot Download the Application. The Application is missing required Files. Contact Application Vendor For Assistance. So I'm building a windows form application using SharpDevelop 5.2 and I'm trying to make a standalone/version someone else would be able to use on another machine. In sharpdevelop (and visual...

WPF style info from external text file

Not sure if this is possible, but I have a WPF application that now has a requirement to be skinnable. Basically, this equates to several key colours and a couple of logos. Is there any way of grabbing the hex values for the colours in defined styles from an external...

How to change background Color of label full length when Mouse Hover in c#

I can't Select label back Ground color Mouse Hover event in full length,only can select The Word length I would like to get log out background same like username background as full width private void label5_MouseHover(object sender, EventArgs e) { this.LblChange.BackgroundImage = null; this.LblChange.BackgroundImage = global::Flex.Properties.Resources.Mail1; this.LblChange.BackColor = Color.Blue; this.LblChange.BackgroundImageLayout...

Syntax error in Insert query in Mysql in VB.Net

I am doing project in VB.NET and backend is mysql Can you please tell me where the error is occured Public Sub ins() con.Open() Dim cmd1 As New OdbcCommand("insert into party values('" + pcode_txt.Text + "','" + Trim(UCase(name_txt.Text)) + "','" + Trim(UCase(addr_txt.Text)) + "','" + phone_txt.Text + "','" + combo_route.SelectedItem...