How do I hide a button when printing? - vb.net

After searching for a solution on the internet, I found this on CodeProject from 2007:
VisibleWhilePrinting = false
This does not seem to exist in VB.Net. Is there something out there that I can use to hide a button when printing a form? (other than manually setting the button's "visible" property to hidden every time the form is printed).
Thanks.

Why don't you create a method that handle's this type of behaviour? The code you provided is probably a variable that is referenced somewhere in the code to determine what needs to take place, for ex:
Dim VisibleWhilePrinting As Boolean = False
Then this can be used or set anywhere and then used where you need it to. In order to hide a button just depends on why you need to hide it. As you have already stated about the visible property of the button itself. So as I have said, create a method and call it or a function...
UPDATE
As #varocarbas has mentioned, there isn't a automatic way of acheiving this, only manually.

Related

Opposite of SetFocus

MSAccess VBA:
Assume, in an arbitrary form, the focus is set to MyControl on that form.
How to "unset" the focus without giving the focus to another control?
I'm lokking for a code like
MyControl.UnsetFocus
In your circumstance, you probably want to just set focus back to the parent form. This meets the conditions of unsetting focus without giving another control focus, and tabbing or clicking will activate the focus / tab-navigation again from that form.
Here's an example:
Forms![MyForm].SetFocus
Note that per the documentation for SetFocus, if you attempt to SetFocus to a Form with child controls that have Enabled set, this will cause focus to automatically bounce to the first eligible child control per the documentation.
Form.SetFocus method (Access) # Microsoft Docs
The option to give focus to the parent form does work as proposed by meklarian
Alternatively, I recently had to do something similar but I wanted to update a textbox value and simply go back to whatever had focus before. This is another case where something like an "unsetfocus" would be awesome, but unfortunately doesn't exist.
Should you need to do something like this, the following works well
Screen.PreviousControl.SetFocus

Reset usercontrol placed on form

Probably simple question but couldn't find any working solution. I have User control on windows form. I would like on button click placed on user control to reload user control. By reload i mean to reset all its variables and show again. How to achieve that?
There is nothing that does that. You could dispose the existing control and create a new one but noone would do that. Basically, it's a manual process. If you want the control's fields reset to defaults then you need to write code to do that. You might declare a Reset method and put all the code in there if that's appropriate and then you can simply call that method from the form.

Excel: Fixed Button Position

Needing some help attaching an Excel/VBA button on an Excel sheet. I need it to stay in the same position on the screen regardless of how I scroll or zoom. Preferably, I need this on the bottom left or right of the screen.
I have tried adding a button. Then, I right clicked on the button. Clicked on Format Controls -> Properties -> selected Don't Move or Size With Cells. Am I missing something that's making this not work?
Thanks!
I know this post is old, but here's to anyone it could be useful. The VisibleRange property of ActiveWindow can solve this problem. Use something like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ActiveSheet.OLEObjects("MY_BUTTON'S_NAME")
.Top = ActiveWindow.VisibleRange.Top + ActiveWindow.VisibleRange.Height - 5
.Left = ActiveWindow.VisibleRange.Left + ActiveWindow.VisibleRange.Width - .Width - 5
End With
End Sub
Here is the idea that I put across the comment earlier today :) Typically we can get a Floating User Form by setting the Modal property of the form to be 0 which is indeed a Modeless state.
Basic Points to consider:
Look & Feel of the form to make it look like a Button (Not show title bar/Not Resizable/
Hidden Close Button etc)
Setting the position of the Button
Which Event should trigger the form-button (WorkBook Open)
What would you do with Form Initialize Event
Whcih Events should keep it stick to the same position alive
Further Points to consider:
You might only want to keep this button vissible for the workbook you are working, and if you open another instance of a workbook, do you still want to keep the button
If you minimize the Excel Window instance, how do you plan to manage the state of the button and keep it visible
Post about keep displaying a form even the workbook is minimized.
One other great reference I happend to see, (little bit technical) but worth the shot - at least to get to know the certain properties/methods that you could make use: Extending VBA User Form Control.
The article include the following info, and please note the last line as well :)
They give you access to capabilities that are not available from VBA or from the objects (UserForms, Workbooks, etc.,) that make up a VBA Project. When you call an API, you are bypassing VBA and calling directly upon Windows. This means that you do not get the safety mechanisms such as type checking that VBA normally provides. If you pass an invalid value to an API or (a very common mistake) use a ByRef parameter instead of a ByVal parameter, you will most likely completely and immediately crash Excel and you will lose all your unsaved work. I recommend that until you are confident that your API calls are solid you save your work before calling an API function.
Add new Row on the beginning of your WorkSheet and set your button on it, then:
Freeze Top Row
Right click → properties → placement → change to 3.

Accessing Datarepeater Button

I have added a button in datarepeater. If clicked once, it executes code and Button.text should change to Yes. Clicked again, it executes the opposite code and button.text should change to No. Codes are being executed (I am using flag variable) but Button.text is not changing.
How to change this text. I am simply trying Button.text="Yes" but probably I need to give some reference of the row no. too. How to do it?
Please advise.
Thanks
Furqan
Please check this question:
Handle Button Click in WinForm DataRepeater C# Power Pack
Also: the CurrentItem property has a property named Controls that allows you to access its child controls like this: CurrentItem.Controls["OKButton"]

vb.net getsettings

I need a form width a checkbox "Don't show this again" for my winform,
but how can i make this so when my Form1 loads it checks the state of the checkbox using the getsettings option?
How can is save the checkbox state to the registery? and how do i get the state?
If Form2.Checkbox.checked = Getsettings() Then
Form2.showdialog
Else
Goto Skip
End IF
Skip:
Windows Forms has built-in support for that, you don't need to write any code. Select your check box. In the Properties window, scroll to the top on expand the "ApplicationSettings" node. Click on "Checked" and drop-down the combobox. Click New. Set the Name property to something meaningful.
Done. Your check box will always restore with the last selection that the user selected. Don't call Show() when it is turned on, dispose the form right away.
The main crux of the question is "how do I read and write value to and from the registry."
See here for a great overview complete with code.
You're beginner so here are a few tips on your code sample:
Name your objects more verbosely. Form2 will mean nothing to you a few hours from now.
Do not use Goto. Just don't. Please. You either show the dialog or you don't. The whole Else block with the Goto in it is just not necessary.
Few more things you'll need to do to get this working:
Handle the CheckBox checked event and write either a 1 or 0 (or T or F) to a registry value
Read that registry value in your GetSettings method
You might want to pass a parameter to GetSettings that specifies exactly which setting you need because you'll probably want to reuse that method for other settings as well